BeanNotOfRequiredTypeException but was actually of type $Proxy

MaximeF picture MaximeF · Oct 14, 2014 · Viewed 28.5k times · Source

I need help with a problem with Spring and proxy.

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'fooAPIService' must be of type [com.foo.clientapi.service.FooAPIService], but was actually of type [com.sun.proxy.$Proxy110]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'activityController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'fooAPIService' must be of type [com.foo.clientapi.service.FooAPIService], but was actually of type [com.sun.proxy.$Proxy110]

Webapp project ->

Spring-context

<context:annotation-config/>
<context:component-scan base-package="com.foo.controller"/>
<aop:aspectj-autoproxy />
<aop:config proxy-target-class="true"/>
<mvc:annotation-driven/>

ActivityController.class

import com.foo.clientapi.service.FooAPIService;
...

@Controller
@RequestMapping(value = "/toto")
public class ActivityController {

@Resource
private FooAPIService fooAPIService;

...
}

Another project (micro-service) ->

FooAPIService.class

@Path("/foos")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface FooAPIService {

...
}

Jaxrs Config:

<jaxrs:client id="fooAPIService"
              address="${toto}"
              threadSafe="true"
              serviceClass="com.foo.clientapi.service.FooAPIService"
              inheritHeaders="true">
    ...
</jaxrs:client>

Version : aspectjweaver : 1.6.10 aspectjrt : 1.6.11 cglib : 2.2 Spring 3.2.2

Answer

MaximeF picture MaximeF · Oct 15, 2014

The problem was that I had two beans(jaxrs:client) with the same id (name).