Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 使用MethodInterceptor包装对受保护方法的调用_Spring_Spring Aop_Aopalliance - Fatal编程技术网

Spring 使用MethodInterceptor包装对受保护方法的调用

Spring 使用MethodInterceptor包装对受保护方法的调用,spring,spring-aop,aopalliance,Spring,Spring Aop,Aopalliance,我希望使用基于XML的Spring配置将对受保护方法的调用封装在第三方类中。我已经从org.springframework.aop.support连接了一些spring类。它对公共方法有效,但对受保护的方法无效: <bean id="sampleAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="proxyT

我希望使用基于XML的Spring配置将对受保护方法的调用封装在第三方类中。我已经从
org.springframework.aop.support
连接了一些spring类。它对公共方法有效,但对受保护的方法无效:

<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>

三党人
桑帕斯
有效的公共方法
不起作用的受保护方法
如何调整此选项以使用受保护的方法?

在注释状态中,Spring AOP代理只能应用于
公共方法

对于JDK代理,这是不可能的,因为代理只有您的目标对象的接口类型,所以您只能通过它的
public
方法与之交互(请记住,接口中声明的所有方法都是
public


使用GGLIB代理,由于代理具有目标对象的类类型,因此可以与其受保护的
方法进行交互。我认为,由于代理机制之间的一致性,他们不允许这样做。

请参阅。您需要使用AspectJ来实现这一点。潜在的问题是什么?我的意思是,从技术上讲,当代理由代理类的包生成时,访问应该没有问题。