Spring AOP proxy which is not
I have two Spring proxies:
<bean id="simpleBean" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="simpleBeanTarget"/>
</property>
<property name="interceptorNames">
<list>
<value>cacheInterceptor</value>
</list>
</property>
</bean>
<bean id="springDao" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="springDaoTarget"/>
<property name="interceptorNames">
<list>
<value>daoInterceptor</value>
</list>
</property>
</bean>
simpleBean works just fine - SpringDao does not.
The SpringDao class is as follows:
public class SpringDao extends JdbcDaoSupport {
private SimpleJdbcTemplate simpleJdbcTemplate;
public SimpleJdbcTemplate getSimpleJdbcTemplate() {
if (simpleJdbcTemplate==null) {
simpleJdbcTemplate= new SimpleJdbcTemplate(getDataSource());
}
return simpleJdbcTemplate;
}
...
And I have unit test autwired, like this:
@Autowired
@Qualifier("springDao")
protected SpringDao springDao;
And the first indication is something wrong: I get this error:
Autofield failed:., Nested exception java.lang.IllegalArgumentException
If I comment on the @Qualifier annotation and run my unit test again, I get the following:
There is no unique bean type ... one bean match is expected but found 2: [springDaoTarget, springDao]
This is what I expected.
So, I changed my auto control to
@Autowired
@Qualifier("springDaoTarget")
protected SpringCustomerCapacityDao springDao;
And added to my unit test:
following: Object proxy = applicationContext.getBean("springDao");
Assert.assertNotNull(proxy);
Assert.assertTrue(proxy instanceof SpringDao);
And the test failed instance, which (for me) means that my proxy server is not my proxy server.
. ? ?
springDaoTarget, :
<bean id="springDaoTarget" class="com.company.SpringDao">
- , Spring - - JDK, . , . , CGLIB, .
, AOP, , CGLIB. JDK , , bean.
Cliff Meyers: Spring AOP: CGLIB JDK?