normandesjr
normandesjr

Reputation: 11

Could not autowire jaxrs client

I have this in my applicationContext.xml (I am using http://cxf.apache.org/jaxrs)

<context:annotation-config />
<context:component-scan base-package="br.com.test" />

<bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />

<jaxrs:client id="testClient"
  serviceClass="br.com.test.ws.InterfaceServiceTest"
  address="http://localhost:8080/ocs-teste-ws-web/services/myservice">

  <jaxrs:providers>
    <ref bean="jsonProvider" />
  </jaxrs:providers>
</jaxrs:client>

I am including the jar with interface in this project but I am getting the following exception:

1318 [localhost-startStop-2] ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someBeanImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: br.com.test.ws.InterfaceServiceTest br.com.test.impl.SomeBeanImpl.interfaceServiceTest; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [br.com.test.ws.InterfaceServiceTest] 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)}

What am I doing wrong?

Thanks.

Upvotes: 1

Views: 3015

Answers (1)

user3011542
user3011542

Reputation: 21

Don't use @Autowired, use @Resource instead, in the class where you are trying to inject your client. Because @Autowired and @Inject

1) Matches by Type 2) Restricts by Qualifiers 3) Matches by Name

And @Resource

1) Matches by Name 2) Matches by Type 3) Restricts by Qualifiers (ignored if match is found by name)

In your case you use a proxy, So the class type isn't what you want. With @Resource you start by find by name.

Upvotes: 2

Related Questions