Spring AOP事物异常 but was actually of type 'com.sun.proxy.$Proxy17
来源:互联网 发布:上海开放大学网络教育 编辑:程序博客网 时间:2024/05/24 03:23
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'CustomerServiceImpl'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'customerServiceImpl' is expected to be of type 'com.yld.service.impl.CustomerServiceImpl' but was actually of type 'com.sun.proxy.$Proxy17'at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4710)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5135)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'customerServiceImpl' is expected to be of type 'com.yld.service.impl.CustomerServiceImpl' but was actually of type 'com.sun.proxy.$Proxy17'
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.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 24 more
遇到这个问题我是因为是serviceimpl实现了service层是接口出现的错误,原因是没有开启动态代理,动态代理的配置如下:
在spring aop 中配置:
<aop:aspectj-autoproxy proxy-target-class="true"/>
记得导入jar包依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
这里有一篇文章讲解了静态代理和动态代理之间的区别。。。有兴趣的可以看一下。
https://www.cnblogs.com/hongcong/p/5806024.html
- Spring AOP事物异常 but was actually of type 'com.sun.proxy.$Proxy17
- BeanNotOfRequiredTypeException 异常:but was actually of type 'com.sun.proxy.$Proxy17'
- 使用spring遇到"BeanNotOfRequiredTypeException......but was actually of type [com.sun.proxy.$Proxy18]"异常
- 使用spring遇到"BeanNotOfRequiredTypeException......but was actually of type [com.sun.proxy.$Proxy18]"异常
- Bean named '*' must be of type [*], but was actually of type [com.sun.proxy.$Proxy34]
- is expected to be of type but was actually of type 'com.sun.proxy.$Proxy70'
- but was actually of type 'com.sun.proxy.$Proxy**'的两种解决方法
- ......but was actually of type [sun.proxy.$Proxy8]
- 解决must be of type [com.bysj.services.CompanyServiceImp], but was actually of type [com.sun.proxy.$Pr
- Bean named 'xxx' must be of type xxx , but was actually of type [com.sun.proxy.$Proxy189]
- BeanNotOfRequiredTypeException: Bean named "" must be of type [] but was actually of type [com.sun.p
- Bean named 'testImpl' must be of type [lcw.serviceimpl.testImpl], but was actually of type [com.sun.
- Getting Spring Error “Bean named 'x' must be of type [y], but was actually of type [$Proxy]” in Jenk
- but was actually of type [$Proxy19]
- BeanNotOfRequiredTypeException: Bean named "" must be of type [] but was actually of type [com.su
- Bean named 'transactionAdvice' must be of type [org.aopalliance.aop.Advice], but was actually of typ
- is expected to be of type 'org.com.ssh.hibernate.AOPService.EchoTest' but was actually of type 'com.
- Bean named 'deptDao' must be of type [com.zttech.sys.dao.IGroupDao], but was actually of type [com.s
- 蓝桥杯 算法训练 传纸条
- 使用Eclipse和Tomcat开发Web程序
- (转)孙正义:数字资产会成为人类最大的资产
- 我在xxx公司的日子(2)
- Java-----分布式锁
- Spring AOP事物异常 but was actually of type 'com.sun.proxy.$Proxy17
- Android样式 Selector
- 【Weblogic】 Weblogic Server环境下使用JMS服务
- 修改vs2010发布包【发布文件】
- 关于sql中出现的三种多线程操作
- uLua使用总结(二)
- LeetCode 714. Best Time to Buy and Sell Stock with Transaction Fee
- Mysql
- Linux环境下在Tomcat上部署JavaWeb工程