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

Closed

Description

@spring-projects-issues

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:

Activity

  1. spring-projects-issues commented on May 7, 2007

    @spring-projects-issues
    CollaboratorAuthor

    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

  2. spring-projects-issues commented on Jun 13, 2007

    @spring-projects-issues
    CollaboratorAuthor

    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?

  3. spring-projects-issues commented on Jun 14, 2007

    @spring-projects-issues
    CollaboratorAuthor

    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

  4. spring-projects-issues commented on Jun 19, 2007

    @spring-projects-issues
    CollaboratorAuthor

    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

  5. added
    in: core
    type: task
    on Jan 11, 2019
  6. added this to the 2.1 M3 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coretype: task

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions