Skip to content

Doc: Using <aop:config> namespace with different 'proxy-target-class' settings for two different objects makes usage of CGLIB proxy only [SPR-3459] #8142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue May 6, 2007 · 4 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 6, 2007

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:

@spring-projects-issues
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task
Projects
None yet
Development

No branches or pull requests

1 participant