标签:
出现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"); } }
标签:
原文地址:http://www.cnblogs.com/rookie404/p/5926047.html