查看: 3667|回复: 0
收起左侧

解决的这个问题记录分享给大家:在Spring整合Struts2中,在Action中注入Service,出现异常的解决

[复制链接]

566

主题

713

帖子

3823

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3823
发表于 2017-11-16 09:59:44 | 显示全部楼层 |阅读模式



Struts Problem Report

Struts has detected an unhandled exception:

Messages:       
Cannot convert value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService': no matching editors or conversion strategy found
Failed to convert property value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService': no matching editors or conversion strategy found
Error creating bean with name 'customerAction' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService': no matching editors or conversion strategy found
Unable to instantiate Action, customerAction, defined for 'customer_list' in namespace '/'Error creating bean with name 'customerAction' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService': no matching editors or conversion strategy found
File:        org/springframework/beans/TypeConverterDelegate.java
Line number:        302
Stacktraces

Unable to instantiate Action, customerAction, defined for 'customer_list' in namespace '/'Error creating bean with name 'customerAction' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService': no matching editors or conversion strategy found - action - file:/C:/workspace/2017_itheima_b/.metadata/.me_tcat7/webapps/day74-demo/WEB-INF/classes/struts.xml:13:65
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:314)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:395)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:554)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:744)
   
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerAction' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService': no matching editors or conversion strategy found
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
    com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:161)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178)
    com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:148)
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:295)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:395)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:554)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:744)
   
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService': no matching editors or conversion strategy found
    org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:591)
    org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)
    org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:204)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1527)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1486)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
    com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:161)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178)
    com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:148)
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:295)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:395)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:554)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:744)
   
java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy28 implementing com.itheima.cust.service.ICustomerService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.itheima.cust.service.impl.CustomerServiceImpl] for property 'customerService': no matching editors or conversion strategy found
    org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:302)
    org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)
    org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)
    org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:204)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1527)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1486)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
    com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:161)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178)
    com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:148)
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:295)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:395)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:554)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:744)
   
You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:

  struts.devMode=false
in your WEB-INF/classes/struts.properties file.



上面就是报的异常信息:

org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy28 implementing

从上面的异常信息可以分析出:肯定出现在需要动态代理的地方。现在再来分析,Service和Dao单独测试都已经没有问题了,那么问题肯定出现在Action中了,配置文件对了一遍没问题,再去看下Action类,发现如下图:






解决方法就是:把Action中的Service的注入改一下,把实现类改为用接口接收。




  1. /**
  2. * Customer模块表现层Action类
  3. */
  4. public class CustomerAction extends ActionSupport implements ModelDriven<Customer>  {
  5.   
  6.   /**
  7.    * Customer模块service层实现类实例对象,由Spring注入
  8.    */
  9.   private ICustomerService customerService;
  10.   public void setCustomerService(ICustomerService customerService) {
  11.     this.customerService = customerService;
  12.   }
  13. }


















































本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 打开微信扫一扫