Repository navigation
Description
Andrei Stefan opened SPR-3459 and commented
Hi,
For the following configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="debuggingAspect" class="com.interceptor.DebugInterceptor" />
<bean id="mock" class="com.objects.AopMockBean">
<property name="prop"><value>666</value></property>
</bean>
<bean id="mock2" class="com.objects.AopMockBean2">
<property name="prop"><value>666</value></property>
</bean>
<aop:config proxy-target-class="false">
<aop:pointcut id="businessManagers"
expression="execution(* com.objects.AopMockBean.displayProp(..))" />
<aop:advisor pointcut-ref="businessManagers" advice-ref="debuggingAspect" />
</aop:config>
<aop:config proxy-target-class="true">
<aop:pointcut id="businessManagers2"
expression="execution(* com.objects.AopMockBean2.displayProp(..))" />
<aop:advisor pointcut-ref="businessManagers2" advice-ref="debuggingAspect" />
</aop:config>
</beans>
from console messages, no JDK proxying is applied, unless both 'proxy-target-class' settings are set to 'false'.
Advices are applied on both classes, only that CGLIB proxying mechanisms is used for both.
This is the test class:
public class AopDebugInterceptorTests2 extends
AbstractDependencyInjectionSpringContextTests {
@Override
protected String[] getConfigLocations() {
return new String[] {"conf/aop/applicationContext.xml"};
}
public void testAop() {
AopMockBeanInterface bean = (AopMockBeanInterface) applicationContext.getBean("mock");
AopMockBeanInterface2 bean2 = (AopMockBeanInterface2) applicationContext.getBean("mock2");
System.out.println("bean 1 property:" + bean.displayProp());
System.out.println("bean 2 property:" + bean2.displayProp());
}
}
This is one of the beans, identical with the second one (second bean implements AopMockBeanInterface2, which is identical with AopMockBeanInterface):
public class AopMockBean implements AopMockBeanInterface {
private String prop;
public String getProp() {
return prop;
}
public void setProp(String prop) {
this.prop = prop;
}
public String displayProp() {
return "1 " + prop;
}
}
public interface AopMockBeanInterface {
public String displayProp();
}
This is the interceptor:
public class DebugInterceptor implements MethodInterceptor {
private static Logger log = Logger.getLogger(DebugInterceptor.class);
public Object invoke(MethodInvocation invocation) throws Throwable {
log.debug("1 Before: invocation=[" + invocation + "]");
Method method = invocation.getMethod();
log.debug("1 getName " + method.getName());
log.debug("1 getArguments " + invocation.getArguments());
Object rval = invocation.proceed();
return rval;
}
}
Tested this configuration using spring-framework-2.0.5-20070506-82.zip jar files.
Affects: 2.0.5
Issue Links:
- Add support for mixed, fine-grained JDK- and CGLIB-based proxying [SPR-3665] #8346 Add support for mixed, fine-grained JDK- and CGLIB-based proxying ("is depended on by")
Activity
spring-projects-issues commentedon May 7, 2007
Juergen Hoeller commented
This is actually the expected behavior: Multiple aop:config sections are collapsed into a single unified auto-proxy creator at runtime, which applies the 'strongest' settings that any of the aop:config sections (typically from different XML bean definition files) specified. This is why you're seeing the CGLIB proxy used for all AOP advices here...
This is probably not explicitly documented anywhere at this point. Hence I'm changing this into a documentation issue, assigned to Rick for the 2.1 timeframe.
Juergen
spring-projects-issues commentedon Jun 13, 2007
Taras Tielkes commented
Juergen,
If I understand correctly, using proxy-target-class="true" on tx:annotation-driven, aop:aspectj-autoproxy or aop:config will force the use of CGLIB proxies for all three of them. Is this a correct summary?
spring-projects-issues commentedon Jun 14, 2007
Juergen Hoeller commented
Yes, this summary is correct. However, as you recently reported, aop:aspectj-autoproxy wasn't behaving as intended there... which will be fixed in 2.0.6 / 2.1 M3.
Juergen
spring-projects-issues commentedon Jun 19, 2007
Rick Evans commented
Fixed. I have added a section to the AOP chapter (in the section entitled 'Proxying mechanisms') detailing this behaviour.
Thanks for raising this, cheers
Rick