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正常工作,所以我错过了什么?