【发布时间】:2016-06-11 22:50:35
【问题描述】:
我有一个非常简单的 JAX-RS 服务:
@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。
当我对 /rest/test 进行 GET 操作时,我得到 500 的响应,内容类型为纯文本/文本,文本为“java.lang.NullPointerException”。但日志或消息中没有更多信息(特别不是 NPE 来自的位置)。
我的生产者方法被调用,但我在 Service 类中的 test() 方法没有。
使用@Named("message") 而不是@Message 可以正常工作,所以我错过了什么?
【问题讨论】:
标签: jakarta-ee jax-rs cdi