spring proxyfactorybean-interceptor/advice有时未调用/丢失

64jmpszr  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(328)

我的 Spring Bean 应该这样称呼:

myProxy -> myDynamicProxy -> myInterceptor -> myService

这在大多数情况下都有效,但有时 myInterceptor 已跳过。

代码/Spring配置:

我的代理

类(伪代码)

public class MyProxy implements MyService {

    private final MyService target;

    public MyProxy(final MyService target) {
        this.target = target;
    }

    @Override
    public void someMethod() {
        target.someMethod();
    }
}

xml格式

<bean id="myProxy" class="com.mp5er.MyProxy">
    <constructor-arg ref="myDynamicProxy"/>
</bean>

mydynamicproxy公司

xml格式

<bean id="myDynamicProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces">
        <value>com.mp5er.MyService</value>
    </property>
    <property name="target">
        <ref bean="myServiceImpl" />
    </property>
    <property name="interceptorNames">
        <list>
            <idref bean="myInterceptor" />
        </list>
    </property>
</bean>

我的拦截器

xml格式

<bean id="myInterceptor"
      class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor">
    <property name="authenticationManager" ref="authenticationManager" />
    <property name="accessDecisionManager" ref="myAccessDecisionManager" />
    <property name="objectDefinitionSource">
        <value>
            myValue
        </value>
    </property>
</bean>

stacktrace(调用methodsecurityinterceptor)

at com.mp5er.MyServiceImpl.someMethod(MyServiceImpl.java:256)
at jdk.internal.reflect.GeneratedMethodAccessor1905.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy240.someMethod(Unknown Source)
at com.mp5er.MyProxy.someMethod(MyProxy.java:91)

stacktrace(未调用methodsecurityinterceptor)

at com.mp5er.MyServiceImpl.someMethod(MyServiceImpl.java:256)
at jdk.internal.reflect.GeneratedMethodAccessor1956.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205)
at com.sun.proxy.$Proxy240.someMethod(Unknown Source)
at com.mp5er.MyProxy.someMethod(MyProxy.java:91)

我无法调试该问题,因为它只发生在生成服务器上。不知怎么的 myDynamicProxy 初始化时没有 myInterceptor . spring调试日志显示,在初始化myinterceptor之后,不会调用proxyfactorybean#advicechanged:

16:09:04,518 INFO  [net.sf.acegisecurity.intercept.AbstractSecurityInterceptor] Validated configuration attributes
16:09:04,518 DEBUG [org.springframework.aop.framework.ProxyFactoryBean] Advice has changed; re-caching singleton instance

spring版本是5.1.15.release,应用程序运行在带有openjdk 11.0.9的tomcat8上。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题