but was actually of type 'com.sun.proxy.$Proxy7'

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zx6571269/article/details/79330495

but was actually of type ‘com.sun.proxy.$Proxy7’

标签(空格分隔): spring


image_1c61i2trje741jdk1sbbv7v1cfs9.png-69kB

二月 11, 2018 12:24:02 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5ce65a89: startup date [Sun Feb 11 12:24:01 CST 2018]; root of context hierarchy
二月 11, 2018 12:24:02 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [bean.xml]
Exception in thread “main” org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘airthmeticDaoImp’ is expected to be of type ‘com.zx.aop.AirthmeticDaoImp’ but was actually of type ‘com.sun.proxy.$Proxy7’
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:378)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1086)
at com.zx.aop.testAop.main(testAop.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

通过配置织入@Aspectj切面

虽然可以通过编程的方式织入切面,但是一般情况下,我们还是使用spring的配置自动完成创建代理织入切面的工作。

通过aop命名空间的声明自动为spring容器中那些配置@aspectJ切面的bean创建代理,织入切面。当然,spring

在内部依旧采用AnnotationAwareAspectJAutoProxyCreator进行自动代理的创建工作,但具体实现的细节已经被<aop:aspectj-autoproxy />隐藏起来了

<aop:aspectj-autoproxy />有一个proxy-target-class属性,默认为false,表示使用jdk动态代理织入增强,当配为<aop:aspectj-autoproxy poxy-target-class="true"/>时,表示使用CGLib动态代理技术织入增强。不过即使proxy-target-class设置为false,如果目标类没有声明接口,则spring将自动使用CGLib动态代理。

image_1c6ev07sjono1eca1lnkhv3c5d9.png-39.1kB

去掉 @serivce,因为这路径还没有把com.zx.aop.AirthmeticDaoImp包含在内,就开始执行了
或者把<aop:aspectj-autoproxy/> 修改成<aop:aspectj-autoproxy proxy-target-class="true"/>

阅读更多
换一批

没有更多推荐了,返回首页