2014-12-27 31 views
0

我正在開發一個JAX-RS項目。 我使用澤西島,Weld和DeltaSpike。注入澤西島,焊接和DeltaSpike失敗

@Path("test") 
public class TestResource { 

    @GET 
    @Path("now") 
    public String now() { 
     return new Date().toString(); 
    } 

    @GET 
    @Path("myProperty") 
    public String myProprety() { 

     return myProperty; 
    } 

    @Inject 
    @ConfigProperty(name = "my.proprety") 
    private String myProperty; 
} 

當我試圖GET /test/myProperty,我得到了。

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at 

回答

2

我必須添加兩個更多的依賴關係才能完成這項工作。

<dependency> 
    <groupId>org.glassfish.jersey.containers.glassfish</groupId> 
    <artifactId>jersey-gf-cdi</artifactId> 
    <version>2.14</version> 
</dependency> 

<dependency> 
    <groupId>javax.transaction</groupId> 
    <artifactId>javax.transaction-api</artifactId> 
    <version>1.2</version> 
</dependency> 
+0

我懷疑這是問題的根源。你如何部署到玻璃魚? –

+0

我不是針對GF的。我的戰爭是針對Apache Tomcat的。 –

0

將資源作爲ManagedBean(或CDI辛格爾頓)這樣的:

@Path("test") 
@ManagedBean 
public class TestResource { 
    ....