I am using Spring in my Java Application, all the @Autowired annotations working until now.
Simplified example would be:
  @Component
  public class MyBean implements MyInterface {
      ...
  }
  @Component
  public class MyOtherBean {
      @Autowired
      private MyBean myBean;
      ...
  }
Once I try to start the Application, I get:
java.lang.IllegalArgumentException: Can not set MyBean field MyOtherBean.myBean to $ProxyXX
implements section, everything works correctly.What can be wrong with the implementation of the interface? What is $ProxyXX?
I suspect the issue is that Spring is injecting an AOP proxy which implements MyInterface - possibly for the purposes of transaction management or caching. Are any of MyBean's methods annotated @Transactional or annotated with any other annotation? 
Ideally you'd probably want to reference MyBean by it's interface type - which should resolve the issue.
@Component
public class MyOtherBean {
    @Autowired
    private MyInterface myBean;
    ...
}
If you have more than one bean implementing MyInterface then you an always qualify your bean by name.
@Component
public class MyOtherBean {
    @Autowired
    @Qualifier("myBean")
    private MyInterface myBean;
    ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With