1

I'm now play around with resteasy to build a rest service, but with the default connectionManager(SimpleHttpConnectionManager), I can only sustain one connection in a long run transactional method. So I try to initialize the bean with MultiThreadedHttpConnectionManager

my 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>

My 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"/>

But when I start my jboss 6 server, I got the following exception:

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    

I try to search dependency version for resteasy package. But the required commons-httpclient is the same(version 3.1). So why is the "HttpClient" cant convert to "HttpClient"?

1 Answers1

1

Finally get this works, the problem is that I adding a 3rd-party dependency:

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

but I didn't specify:

    <scope>provided</scope>

which will resulted the commons-httpclient-3.1.jar will complied in the final war file.

And at the same time, I add commons-httpclient-3.1.jar in the {jboss_home}/server/default/lib directory. So jboss classloader will load httpclient when boot up, and when loading those beans, httpclient will been loaded from the package, which will resulted in the exception above.

So always be aware of those 3rd-party dependency, I think like 90% of those cant convert from same Object to same Object exception is cause by this duplicate loader issue.