cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Curtis Garman" <curt.gar...@gmail.com>
Subject Trouble wiring cxf 3.0 client into spring app
Date Wed, 15 Oct 2014 16:19:32 GMT
I having trouble wiring a cxf jaxrs client into my spring application. I'm
using spring 4.1.1 and cxf 3.0.1. See the java/configuration/log below.
Basically it seems that the clients are not available at the point spring
tries autowire things. However I noticed that if I move my
context:component-scan below the client config things seem to wire up
correctly. This seems strange to me because I've always been under the
impression that the order beans are defined in the configuration doesn't
matter because spring creates the beans in the correct order.

 

 

package test.webservice.rest.service;

 

import test.webservice.rest.domain.Album;

import test.webservice.rest.domain.Track;

 

import java.util.ArrayList;

import java.util.List;

 

import org.apache.cxf.jaxrs.client.WebClient;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.stereotype.Service;

 

@Service

public class SimpleAlbumService implements AlbumService {

 

    @Autowired

    @Qualifier("albumClient")

    private WebClient client;

 

    @Override

    public Album findAlbum(long albumId) {

        return client.path("{album}", albumId).get(Album.class);

    }

 

    @Override

    public List<Album> findAlbums() {

        return new ArrayList<Album>(client.getCollection(Album.class));

    }

 

}

 

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 
xmlns:context="http://www.springframework.org/schema/context"

                xmlns:cxf="http://cxf.apache.org/core"

                xmlns:jaxrs-client="http://cxf.apache.org/jaxrs-client"

                xsi:schemaLocation="

                                http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd

                               http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd

                               http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd

                               http://cxf.apache.org/jaxrs-client
http://cxf.apache.org/schemas/jaxrs-client.xsd">

 

                <import resource="classpath:META-INF/cxf/cxf.xml"/>

                <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

 

                <context:component-scan
base-package="test.webservice.rest.service" />

                

                <bean id="jsonProvider"
class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>

 

    <jaxrs-client:client id="albumClient"

                serviceClass="org.apache.cxf.jaxrs.client.WebClient"

 
address="http://localhost:8080/rest-provider/services/album"

                                <jaxrs-client:headers>

                                                <entry key="Accept"
value="application/xml"/>

                                </jaxrs-client:headers>

                <jaxrs-client:providers>

                                <ref bean="jsonProvider" />

                                </jaxrs-client:providers>

                </jaxrs-client:client>

 

</beans>

 

 

INFO [localhost-startStop-1] Oct/15 10:51:51,832
org.springframework.web.context.ContextLoader.[] - Root
WebApplicationContext: initialization started

INFO [localhost-startStop-1] Oct/15 10:51:51,941
org.springframework.web.context.support.XmlWebApplicationContext.[] -
Refreshing Root WebApplicationContext: startup date [Wed Oct 15 10:51:51 CDT
2014]; root of context hierarchy

INFO [localhost-startStop-1] Oct/15 10:51:51,972
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.[] - Loading
XML bean definitions from ServletContext resource
[/WEB-INF/classes/context/jaxrs.xml]

INFO [localhost-startStop-1] Oct/15 10:51:52,004
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.[] - Loading
XML bean definitions from class path resource [META-INF/cxf/cxf.xml]

INFO [localhost-startStop-1] Oct/15 10:51:52,019
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.[] - Loading
XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]

WARN [localhost-startStop-1] Oct/15 10:51:52,456
org.springframework.web.context.support.XmlWebApplicationContext.[] -
Exception encountered during context initialization - cancelling refresh
attempt

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'simpleAlbumService': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private org.apache.cxf.jaxrs.client.WebClient
test.webservice.rest.service.SimpleAlbumService.client; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [org.apache.cxf.jaxrs.client.WebClient] 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),
@org.springframework.beans.factory.annotation.Qualifier(value=albumClient)}

                at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
essor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:32
6)

                at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.populateBean(AbstractAutowireCapableBeanFactory.java:1204)

                at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)

                at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.createBean(AbstractAutowireCapableBeanFactory.java:476)

                at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(Ab
stractBeanFactory.java:302)

                at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSi
ngleton(DefaultSingletonBeanRegistry.java:229)

                at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abst
ractBeanFactory.java:298)

                at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstra
ctBeanFactory.java:193)

                at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInst
antiateSingletons(DefaultListableBeanFactory.java:725)

                at
org.springframework.context.support.AbstractApplicationContext.finishBeanFac
toryInitialization(AbstractApplicationContext.java:757)

                at
org.springframework.context.support.AbstractApplicationContext.refresh(Abstr
actApplicationContext.java:480)

                at
org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicat
ionContext(ContextLoader.java:403)

                at
org.springframework.web.context.ContextLoader.initWebApplicationContext(Cont
extLoader.java:306)

                at
org.springframework.web.context.ContextLoaderListener.contextInitialized(Con
textLoaderListener.java:106)

                at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:
4760)

                at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:
5184)

                at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

                at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:7
24)

                at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)

                at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)

                at
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1071)

                at
org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1
722)

                at
java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

                at java.util.concurrent.FutureTask.run(Unknown Source)

                at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown
Source)

                at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

                at java.lang.Thread.run(Unknown Source)

Caused by: org.springframework.beans.factory.BeanCreationException: Could
not autowire field: private org.apache.cxf.jaxrs.client.WebClient
test.webservice.rest.service.SimpleAlbumService.client; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [org.apache.cxf.jaxrs.client.WebClient] 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),
@org.springframework.beans.factory.annotation.Qualifier(value=albumClient)}

                at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
essor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java
:542)

                at
org.springframework.beans.factory.annotation.InjectionMetadata.inject(Inject
ionMetadata.java:87)

                at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
essor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:32
3)

                ... 26 more

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [org.apache.cxf.jaxrs.client.WebClient] 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),
@org.springframework.beans.factory.annotation.Qualifier(value=albumClient)}

                at
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNo
SuchBeanDefinitionException(DefaultListableBeanFactory.java:1261)

                at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResol
veDependency(DefaultListableBeanFactory.java:1009)

                at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolve
Dependency(DefaultListableBeanFactory.java:904)

                at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
essor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java
:514)

                ... 28 more

ERROR [localhost-startStop-1] Oct/15 10:51:52,456
org.springframework.web.context.ContextLoader.[] - Context initialization
failed

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'simpleAlbumService': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private org.apache.cxf.jaxrs.client.WebClient
test.webservice.rest.service.SimpleAlbumService.client; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [org.apache.cxf.jaxrs.client.WebClient] 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),
@org.springframework.beans.factory.annotation.Qualifier(value=albumClient)}

                at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
essor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:32
6)

                at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.populateBean(AbstractAutowireCapableBeanFactory.java:1204)

                at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)

                at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.createBean(AbstractAutowireCapableBeanFactory.java:476)

                at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(Ab
stractBeanFactory.java:302)

                at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSi
ngleton(DefaultSingletonBeanRegistry.java:229)

                at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abst
ractBeanFactory.java:298)

                at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstra
ctBeanFactory.java:193)

                at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInst
antiateSingletons(DefaultListableBeanFactory.java:725)

                at
org.springframework.context.support.AbstractApplicationContext.finishBeanFac
toryInitialization(AbstractApplicationContext.java:757)

                at
org.springframework.context.support.AbstractApplicationContext.refresh(Abstr
actApplicationContext.java:480)

                at
org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicat
ionContext(ContextLoader.java:403)

                at
org.springframework.web.context.ContextLoader.initWebApplicationContext(Cont
extLoader.java:306)

                at
org.springframework.web.context.ContextLoaderListener.contextInitialized(Con
textLoaderListener.java:106)

                at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:
4760)

                at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:
5184)

                at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

                at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:7
24)

                at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)

                at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)

                at
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1071)

                at
org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1
722)

                at
java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

                at java.util.concurrent.FutureTask.run(Unknown Source)

                at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown
Source)

                at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

                at java.lang.Thread.run(Unknown Source)

Caused by: org.springframework.beans.factory.BeanCreationException: Could
not autowire field: private org.apache.cxf.jaxrs.client.WebClient
test.webservice.rest.service.SimpleAlbumService.client; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [org.apache.cxf.jaxrs.client.WebClient] 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),
@org.springframework.beans.factory.annotation.Qualifier(value=albumClient)}

                at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
essor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java
:542)

                at
org.springframework.beans.factory.annotation.InjectionMetadata.inject(Inject
ionMetadata.java:87)

                at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
essor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:32
3)

                ... 26 more

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [org.apache.cxf.jaxrs.client.WebClient] 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),
@org.springframework.beans.factory.annotation.Qualifier(value=albumClient)}

                at
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNo
SuchBeanDefinitionException(DefaultListableBeanFactory.java:1261)

                at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResol
veDependency(DefaultListableBeanFactory.java:1009)

                at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolve
Dependency(DefaultListableBeanFactory.java:904)

                at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
essor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java
:514)

                ... 28 more

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message