java – 使用Maven的Spring 3.0.5使用Jersey 1.6

我很难让Jersey使用Spring 3.0.5.我发现很多人说他们能够使它工作但我运气不好.我总是得到:

java.lang.NoSuchMethodError:org.springframework.web.context.ConfigurableWebApplicationContext.setId(Ljava / lang / String;)

有人能够做到这一点吗?

谢谢您的帮助!

这是我的pom依赖项:

<dependencies>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${jersey-version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-spring</artifactId>
        <version>${jersey-version}</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-core</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-aop</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-beans</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-context</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-web</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>
</dependencies>

这是错误:

GRAVE: Exception while loading the app
java.lang.Exception:
java.lang.IllegalStateException:
ContainerBase.addChild: start:
org.apache.catalina.LifecycleException:
java.lang.NoSuchMethodError:
org.springframework.web.context.ConfigurableWebApplicationContext.setId(Ljava/lang/String;)V
at
com.sun.enterprise.web.WebApplication.start(WebApplication.java:117)
at
org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
at
org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
at
org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
at
org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:310)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
at
org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:141)
at
org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:573)
at
org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:459)
at
org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:391)
at
org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:376)
at
org.glassfish.deployment.autodeploy.AutoDeployService$1.run(AutoDeployService.java:195)
at
java.util.TimerThread.mainLoop(Timer.java:512)
at
java.util.TimerThread.run(Timer.java:462)

解决方法:

做一个mvn依赖:树并确保没有更多版本的Spring从其他地方进入. ConfigurableWebApplicationContext.setId()在Spring 2.5中不存在,但它在3.x中存在.

上一篇:java – 它是JAX-RS中UriBuilder的正确行为吗?


下一篇:java – 在Osgi中以编程方式注册ServletContainer