出现org.springframework.aop.framework.ProxyFactoryBean cannot be cast to 错误
在类型转换的时候, 调用getObject()方法,再对ProxyFactoryBean进行转换
xml文件
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy><!--使用cglib动态代理--> <bean id="greetingProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="interfaces" value="xxxx"></property><!--代理接口--> <property name="target" ref="xxxx"></property><!--接口的实现类--> <property name="interceptorNames" value="greetingAroundAdvice"></property><!--引入增强--> </bean>
环绕增强类:
@Aspect @Component public class GreetingAroundAdvice implements MethodInterceptor{ @Override public Object invoke(MethodInvocation invocation) throws Throwable { before(); Object result = invocation.proceed(); after(); return result; } private void before() { System.out.println("before"); } private void after() { System.out.println("after"); } }
时间: 2024-11-10 01:35:11