在 Contexts and Dependency Injection (CDI) 1.0 實作中,實作 javax.enterprise.inject.spi.InjectionPoint 介面之類別中的 getAnnotated 方法,可能會傳回 javax.enterprise.inject.spi.Annotated 的實例。在 CDI 1.2 實作中,getAnnotated 方法必須傳回 AnnotatedField 或 AnnotatedParameter 的實例,取決於注入點是注入的欄位還是建構子或方法中的參數。
此規則會標示對實作 javax.enterprise.inject.spi.InjectionPoint 介面之類別中的 getAnnotated 方法內 Annotated 建構子的呼叫。例如,將會標示對 new Annotated() 的下列呼叫:
public class MyInjectionPoint implements InjectionPoint {
public Annotated getAnnotated() {
return new Annotated() {
public Set<Annotation> getAnnotations() {
return null;
}
...
};
}
...
}
二進位應用程式掃描器會標示用於實作 javax.enterprise.inject.spi.InjectionPoint 介面的類別的所有 getAnnotated 方法。如果已標示的 getAnnotated 方法傳回 AnnotatedParameter 或 AnnotatedField 的實例,則可以忽略此規則。如果 getAnnotated 方法傳回 Annotated 的實例,則必須變更程式碼。
在 CDI 1.2 實作中,包含 MyInjectionPoint 類別的應用程式不會啟動,並且會擲出下列異常狀況:
org.jboss.weld.exceptions.IllegalArgumentException:WELD-001521: InjectionPoint.getAnnotated() 必須傳回 AnnotatedParameter 或 AnnotatedField
若要解決此問題,請將對 new Annotated() 的呼叫取代為對 new AnnotatedField() 或 new AnnotatedParameter() 的呼叫,取決於注入點是注入的欄位還是建構子或方法中的參數。
如需 Java EE 7 CDI 1.2 實作的相關資訊,請參閱 Contexts and Dependency Injection 1.2 行為變更。