2016-06-11 73 views
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正常工作,所以我錯過了什麼?

回答

2

tldr;將@Message放入包中。

所以,你可能猜到這是一個玩具的例子來測試一些東西,我把它扔在默認包中。

Hibernate驗證器不處理默認包中的註釋,因爲它假定會有一個包。

相關問題