Search code examples
springproxy-classes

Why proxy is not used to autowire


I can not find any reason why every autowired bean are not autowired by proxy. I know that becasue @Transactional annotations do not work and I checked autowired component during debugging in eclipse. Of course every component implements some interface and I use @Autowired annotations in relation to the interface. I have only one configuration of aop:

<tx:annotation-driven transaction-manager="transactionManager" />

I use JPA with hibernate, spring-mvc,spring-webflow, spring-security and spring-data. Interfaces which extends org.springframework.data.repository.CrudRepository are autowired by proxy. But my components are not. For example I have class MyClass which implement MyInterface:

@Service
public class MyClass implements MyInterface {
@Autowired
MyCrudReposiotry reposiotry;
....
}

If I autowire MyInterface somewhere:

@Autowired
MyInterface mi;

then mi is just reference to MyClass object, repository is refrence to proxy org.springframework.aop.framework.JdkDynamicAopProxy. Very interesting is that in testing mi is reference to proxy. My test's context does not contain web-flow and mvc configuration.

Maybe there is some indirect aop configuration which I should check. What can switch the autowiring by proxy off?


Solution

  • My guess is that you are scanning for the same components twice. You probably have a in your root context (for the ContextLoaderListener) and one for the DispatcherServlet. NO if the both scan for the same classes you end up with duplicated (and one proxied and one non proxied instance).