Jersey,Weld和DeltaSpike注射失败

时间:2014-12-27 09:37:22

标签: jersey cdi weld deltaspike

我正在开发一个JAX-RS项目。 我使用Jersey,Weld和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 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

使资源成为ManagedBean(或cdi Singleton):

@Path("test")
@ManagedBean
public class TestResource {
    ....
相关问题