spring默认注入方式引起的异常

Failed to convert property value of type [$Proxy0] to required type [com.travis.service.impl.userServiceImpl] for property 'service'

spring默认的注入为接口注入方式。 

2011-8-17 11:47:27 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userListAction' defined in URL [file:/D:/programe/Tomcat6.0/webapps/SSH2Demo/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [com.travis.service.impl.userServiceImpl] for property 'service'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [com.travis.service.impl.userServiceImpl] for property 'service': no matching editors or conversion strategy found
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:448)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [com.travis.service.impl.userServiceImpl] for property 'service'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [com.travis.service.impl.userServiceImpl] for property 'service': no matching editors or conversion strategy found
	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1287)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1248)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
	... 38 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [com.travis.service.impl.userServiceImpl] for property 'service': no matching editors or conversion strategy found
	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)
	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
	... 42 more
2011-8-17 11:47:27 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2011-8-17 11:47:27 org.apache.catalina.core.StandardContext start
严重: Context [/SSH2Demo] startup failed due to previous errors
2011-8-17 11:47:27 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2011-8-17 11:47:28 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8088
2011-8-17 11:47:28 org.apache.catalina.loader.WebappClassLoader loadClass
信息: Illegal access: this web application instance has been stopped already.  Could not load com.mysql.jdbc.SQLError.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1244)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3134)
	at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1616)
	at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4223)
	at com.mysql.jdbc.ConnectionImpl.cleanup(ConnectionImpl.java:1257)
	at com.mysql.jdbc.ConnectionImpl.finalize(ConnectionImpl.java:2663)
	at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
	at java.lang.ref.Finalizer.runFinalizer(Unknown Source)
	at java.lang.ref.Finalizer.access$100(Unknown Source)
	at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)
2011-8-17 11:47:28 org.apache.jk.common.ChannelSocket init

 

1.spring 配置中遇到该问题,可以通过注入的方式解决,代码如下:

    • <tx:annotation-driven transaction-manager="myTxManager" proxy-target-class="true"/>
2.我们想用实现类进行注入,需要做两方面的工作:

     1.导入CGLIB库,即cglib.jar包

     2.在spring配置文件applicationContext.xml中进行一下配置:<aop:aspectj-autoproxy proxy-target-class="true"/> 或者   <aop:config proxy-target-class="true" ></aop:config>表示可以用类注入

 

实际上,上面几种配置解决方法,我一条也没成功..不知是我版本问题还是什么..

但是依据最上面对spring默认注入方式的解释,我发现是因为在我的action中定义service时,我按快捷键导入包导入的是实现类userServiceImpl而不是接口userService,更改之后可以正常启动tomcat。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值