2012-07-20 27 views
1

現在我與RestEasy的建立一個休息服務玩耍,但默認的ConnectionManager(SimpleHttpConnectionManager),我只能保持在一個長期運行的事務方法的一個連接。所以我儘量豆與MultiThreadedHttpConnectionManagerMultiThreadedHttpConnectionManager不能注入到服務

我POM初始化:

<properties> 
    <resteasy.version>2.1.0.GA</resteasy.version> 
    <spring.version>3.0.5.RELEASE</spring.version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 
<dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-beans</artifactId> 
     <version>3.0.5.RELEASE</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>3.0.5.RELEASE</version> 
     <scope>provided</scope> 
    </dependency> 
<dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-spring</artifactId> 
     <version>${resteasy.version}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jackson-provider</artifactId> 
     <version>${resteasy.version}</version> 
     <scope>provided</scope> 
    </dependency> 

我的applicationContext.xml

<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"> 
    <constructor-arg> 
     <bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" 
      p:maxConnectionsPerHost="10" 
      p:maxTotalConnections="20"/> 
    </constructor-arg> 
</bean> 
<bean id="myRestService" 
    class="org.jboss.resteasy.client.spring.RestClientProxyFactoryBean" 
    p:serviceInterface="com.me.service.myRestService" 
    p:baseUri="${serviceNameUrl}" 
    p:httpClient-ref="restHttpClient"/> 

但是當我開始我的JBoss 6服務器,我得到了以下異常:

09:37:44,774 ERROR [ContextLoader] Context initialization failed: org.springframework.beans.factory.BeanCreationException:nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.me.service.myRestService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
Related cause: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'myRestService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: 
Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: 
Failed to convert property value of type 'org.apache.commons.httpclient.HttpClient' to required type 'org.apache.commons.httpclient.HttpClient' for property 'httpClient'; 
nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.apache.commons.httpclient.HttpClient] to required type [org.apache.commons.httpclient.HttpClient] for property 'httpClient': 
no matching editors or conversion strategy found  

我嘗試搜索的依賴版本RestEasy的包。但所需的commons-httpclient是相同的(3.1版)。那麼,爲什麼是「HttpClient的」傾斜轉換爲「HttpClient的」?

回答

1

終於得到這個工作的,問題是,我加入一個第三方的依賴:

<dependency> 
    <groupId>net.java.dev.jets3t</groupId> 
    <artifactId>jets3t</artifactId> 
     <version>0.8.0</version> 
</dependency> 

,但我沒有具體說明:

<scope>provided</scope> 

這將導致公地httpclient- 3.1.jar將在最終的戰爭文件中得到遵守。

,並在同一時間,我想補充的{JBOSS_HOME}公地httpclient的-3.1.jar /服務器/缺省的/ lib目錄下。所以,當開機,並加載這些bean時,HttpClient的將被從包中,這將導致異常上面加載的JBoss的類加載器將加載的HttpClient。

所以總是知道那些第三方的依賴,我覺得像那些不能由同一對象轉換爲同一對象的異常,90%是通過這種重複加載問題的原因。