需要Jersey Tomcat CDI依赖项解释

时间:2018-02-04 17:54:33

标签: java tomcat servlets jersey jax-rs

经过多次试验和错误,我能够创建启用了DI的Jersey应用程序。这就是我在pom.xml文件中的内容:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>2.26</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>       
<dependencies>

    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
    </dependency>   

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.ext.cdi</groupId>
        <artifactId>jersey-cdi1x-servlet</artifactId>
    </dependency>

    <!--dependency>
        <groupId>org.glassfish.jersey.ext.cdi</groupId>
        <artifactId>jersey-weld2-se</artifactId>
    </dependency        -->

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>2.0-EDR1</version>
    </dependency>        

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet-shaded</artifactId>
        <version>3.0.2.Final</version>
    </dependency>               

    <!-- dependency>
        <groupId>org.glassfish.jersey.containers.glassfish</groupId>
        <artifactId>jersey-gf-cdi-ban-custom-hk2-binding</artifactId>
        <version>2.14</version>
    </dependency  -->

</dependencies>

据我所知,cdi-api是DI的API,weld-servlet-shaded是它在Servlet环境中的实现。 jersey-media-json-jackson用于将Java类转换为JSON。 jersey-container-servletjersey-server设置泽西岛。

jersey-hk2看起来像是Oracle的DI实现,CDI的替代品,jersey-cdi1x-servlet在Servlet环境中启用它。

根据How to integrate JAX-RS with CDI in a Servlet 3.0 container,需要jersey-gf-cdi-ban-custom-hk2-binding来禁用某些内容(?),但我不需要这样做。

我的问题是,为什么在jersey-hk2时使用weld-servlet-shaded?他们为什么不冲突?是否有可能以不同的方式进行设置?

0 个答案:

没有答案