本文介绍了Glassfish上的Jersey + Spring部署失败:CDI问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置Glassfish + Spring配置.请在下面找到我pom的相关部分:

I'm tryng to setup a Glassfish + Spring configuration. Please find below the relevant part of my pom :

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

<dependencies>

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

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-spring3</artifactId>
        <!--<scope>provided</scope>-->
    </dependency>


    <dependency>
        <groupId>org.eclipse.birt.runtime</groupId>
        <artifactId>org.eclipse.birt.runtime</artifactId>
        <version>4.2.0</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-grizzly2-http</artifactId>
        <version>${jersey.version}</version>
        <scope>provided</scope>
    </dependency>


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.9</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.easytesting</groupId>
        <artifactId>fest-assert-core</artifactId>
        <version>2.0M10</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1100-jdbc41</version>
        <scope>test</scope>
    </dependency>

我有以下依赖性问题:

 <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-spring3</artifactId>
        <!--<scope>provided</scope>-->
    </dependency>

当我按提供的方式指定此依赖项时,部署可以..但未初始化SPring上下文.如果我评论provided元素,则有时部署可以,应用程序运行正常,但有时部署将失败,并且我将收到以下WELD-001408异常:

When I specify this dependency as provided, deployment is OK.. but SPring context isn't initialized. If I comment the provided element, then sometimes deployment is OK and the application is running fine, but sometimes deplyment will fail and I will get following WELD-001408 exception :

    [2014-12-16T10:21:07.618+0100] [glassfish 4.0] [SEVERE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid: _ThreadID=34 _ThreadName=admin-listener(3)] [timeMillis: 1418721667618] [levelValue: 1000] [[
  Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [IterableProvider<DefaultTopicDistributionErrorService>] with qualifiers [@Default] at injection point [[BackedAnnotatedField] @Inject private org.glassfish.hk2.internal.DefaultTopicDistributionService.errorHandlers]
    at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:225)
    at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [IterableProvider<DefaultTopicDistributionErrorService>] with qualifiers [@Default] at injection point [[BackedAnnotatedField] @Inject private org.glassfish.hk2.internal.DefaultTopicDistributionService.errorHandlers]
    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:403)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:325)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:177)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:208)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:519)
    at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:505)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:480)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:536)
    at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:216)
    ... 36 more
]]

我已经看到很多与此有关的问题,但是我仍然没有找到正确的方法...我想要的是一个使用Jersey提供的REST API,它具有Spring CDI的优点(理想情况下没有xml spring配置).

I've seen many issues regarding this, but I still don't get what is the right way to go...What I want is a REST API built with Jersey, with the benefits of Spring CDI (ideally no xml spring config).

我应该在POM中进行哪些修改才能使其正常工作?

What should I modify in my POM to make it work ?

谢谢.

推荐答案

您可能是此问题的受害者: https://issues.jboss.org/browse/CDI-377

You're probably victim of this issue: https://issues.jboss.org/browse/CDI-377

我只是在猜测,因为您没有提供所使用的Glassfish版本.此问题已在Glassfish 4.1中包含的CDI 1.2中修复.因此最好的解决方案是将其更新到该版本.

I'm just guessing since you didn't provide the version of Glassfish you are using.This issue has been fixed in CDI 1.2 which is included in Glassfish 4.1. So the best solution would be to update to this version.

如果您不能或不想更新,则可以使用以下解决方法: http ://weld.cdi-spec.org/documentation/#4

If you can't or don't want to update you can use this workaround: http://weld.cdi-spec.org/documentation/#4

这篇关于Glassfish上的Jersey + Spring部署失败:CDI问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 19:55