1
我有一個非常簡單的JAX-RS服務:從@Named移動到自定義的限定導致NPE
@Path("/test")
public class Service {
@Inject
@Message
String thingie;
@GET
public String test(){
return thingie;
}
}
如果該字符串出來一個@Produces註解的方法:
public class Producer {
@Produces
@Message
public String thingie(){
return "thingie";
}
}
的@message預選賽看起來是這樣的:
@Qualifier
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface Message {
}
爲了完整起見,其他代碼我已經是一個JAX-RS Activator類:
@ApplicationPath("/rest")
public class JAXRSActivator extends Application {
}
還有一個空的beans.xml。我使用的應用服務器是Wildfly 10.0.10。
當我進行GET/rest/test時,得到的響應爲500,其內容類型爲plain/text和「java.lang.NullPointerException」的文本。但是在日誌或消息中沒有更多的信息(特別是不是NPE來自的位置)。
我的生產者方法被調用,但是我的service類中的test()方法沒有。
它使用@Named(「message」)而不是@Message正常工作,所以我錯過了什麼?