0

I would like to use XML based Spring configuration to wrap calls to a protected method in a 3rd party class. I have wired up some spring classes from org.springframework.aop.support. It works for public methods, but it fails for protected ones:

<bean id="sampleAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="proxyTargetClass" value="true" />
<property name="beanNames">
    <list>
        <value>thrirdPartyBean</value>
    </list>
</property>
<property name="interceptorNames">
    <list>
        <value>sampleAdvisor</value>
    </list>
</property>
</bean>
<bean id="sampleMethodNamePointcut" class="org.springframework.aop.support.NameMatchMethodPointcut">
    <property name="mappedNames">
        <list>
            <value>publicMethodThatWorks</value>
            <value>protectedMethodThatDoesNotWork</value>
        </list>
    </property>
</bean>
<bean id="sampleAdvice" class="sample.MyMethodInterceptor" />
<bean id="sampleAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
    <property name="pointcut" ref="sampleMethodNamePointcut" />
    <property name="advice" ref="sampleAdvice" />
</bean>

How can I tweak this to work with protected methods ?

Andreas Steffan
  • 6,039
  • 2
  • 23
  • 25
  • See http://stackoverflow.com/questions/15093894/aspectj-pointcut-for-annotated-private-methods. You would need to use AspectJ for that. – jny Mar 31 '14 at 16:41
  • What is the underlying problem ? I mean technically, access should be no problem when the proxy is generated the package of the proxied class. – Andreas Steffan Mar 31 '14 at 17:33

1 Answers1

0

As the linked question/answer in the comments states, Springs AOP proxies can only apply to public methods.

With JDK proxies, this isn't possible because the proxy only has your target object's interface types so you can only interact with it through its public methods (remember that all methods declared in an interface are public).

With GGLIB proxies, because the proxy does have the target object's class type, you can interact with its protected methods. I would think for reasons of consistency between proxying mechanisms they would not allow it.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724