Resteasy 3 与 Spring 3 的集成不起作用 [英] Resteasy 3 integration with Spring 3 not working

查看:69
本文介绍了Resteasy 3 与 Spring 3 的集成不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Resteasy 和 Spring 的项目.之前用的Resteasy版本是2.3.5,运行正常,没问题.但是我最近将 Resteasy 版本升级到了 3.0.3.Final,当我部署到 jboss 时它抛出了一些异常.

I have a project which uses Resteasy and Spring. Before I used the Resteasy version is 2.3.5, which worked fine and no problem. However I recently upgraded the Resteasy version to 3.0.3.Final, when I deployed to jboss it throws some exceptions.

没有任何改变,只是 resteasy 版本更改为 3.0.3.Final.

Nothing changed just the resteasy version change to 3.0.3.Final.

例外:

ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-7) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultRestService' defined in "/content/myservice.war/WEB-INF/classes/com/litianhao/resteasy/service/DefaultRestService.class": Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.jboss.resteasy.spi.InjectorFactory.createPropertyInjector(Ljava/lang/Class;Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)Lorg/jboss/resteasy/spi/PropertyInjector;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.jboss.resteasy.plugins.spring.SpringContextLoaderListener.contextInitialized(SpringContextLoaderListener.java:44) [resteasy-spring-3.0.3.Final.jar:]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_07]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_07]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]
Caused by: java.lang.NoSuchMethodError: org.jboss.resteasy.spi.InjectorFactory.createPropertyInjector(Ljava/lang/Class;Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)Lorg/jboss/resteasy/spi/PropertyInjector;
    at org.jboss.resteasy.plugins.spring.SpringBeanProcessor$ResteasyBeanPostProcessor.getInjector(SpringBeanProcessor.java:152) [resteasy-spring-3.0.3.Final.jar:]
    at org.jboss.resteasy.plugins.spring.SpringBeanProcessor$ResteasyBeanPostProcessor.postProcessAfterInitialization(SpringBeanProcessor.java:143) [resteasy-spring-3.0.3.Final.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    ... 20 more

21:48:26,207 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myservice]] (MSC service thread 1-7) Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.spring.SpringContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultRestService' defined in "/content/myservice.war/WEB-INF/classes/com/litianhao/resteasy/service/DefaultRestService.class": Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.jboss.resteasy.spi.InjectorFactory.createPropertyInjector(Ljava/lang/Class;Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)Lorg/jboss/resteasy/spi/PropertyInjector;

Maven pom 文件在这里:

Maven pom file is here:

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Resteasy -->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>${resteasy.version}</version>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>org.jboss.resteasy</groupId>-->
        <!--<artifactId>resteasy-jaxb-provider</artifactId>-->
        <!--<version>${resteasy.version}</version>-->
    <!--</dependency>-->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>${resteasy.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-spring</artifactId>
        <version>${resteasy.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jaxb-impl</artifactId>
                <groupId>com.sun.xml.bind</groupId>
            </exclusion>
            <exclusion>
                <artifactId>sjsxp</artifactId>
                <groupId>com.sun.xml.stream</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jsr250-api</artifactId>
                <groupId>javax.annotation</groupId>
            </exclusion>
            <exclusion>
                <artifactId>activation</artifactId>
                <groupId>javax.activation</groupId>
            </exclusion>
        </exclusions>
    </dependency>

web.xml 文件是:

The web.xml file is:

<listener>
    <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>

<listener>
    <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:spring/applicationContext.xml
    </param-value>
</context-param>

<servlet>
    <servlet-name>resteasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>resteasy</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

推荐答案

对我来说,这个问题是由于没有正确升级 resteasy-spring 3.如果您将 Maven 构建从 2.x 更新到 3.x,您需要替换 JBoss 中使用的 resteasy 模块.要在 Jboss 7 中升级 Resteasy,请下载 resteasy-jaxrs-3.x.x 并解压缩 resteasy-jboss-modules-3,x,x.zip.将/jboss/modules/xxx 替换为 resteasy-jboss-modules-3.x.x.zip 中给定的内容

For me, this problem was from not upgrading resteasy-spring 3 correctly. If you update the maven build from 2.x to 3.x you need to replace the resteasy modules that are used in JBoss. To upgrade Resteasy in Jboss 7, download resteasy-jaxrs-3.x.x and unzip the resteasy-jboss-modules-3,x,x.zip. Replace /jboss/modules/xxx with the ones in the given one in resteasy-jboss-modules-3.x.x.zip

这篇关于Resteasy 3 与 Spring 3 的集成不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆