这几天总算弄明白了ssh的整个架构,于是便决定小试牛刀,但是,异常总是无处不在,当我从load一个user的时候,发现了如下问题
Unable to instantiate Action, com.bjsxt.registration.action.UserAction, defined for 'user' in namespace '/'Failed to convert property value of type [com.bjsxt.registration.action.UserAction] to required type [com.bjsxt.registration.model.User] for property 'user'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.bjsxt.registration.action.UserAction] to required type [com.bjsxt.registration.model.User] for property 'user': no matching editors or conversion strategy found com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:307) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
root cause
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.bjsxt.registration.action.UserAction] to required type [com.bjsxt.registration.model.User] for property 'user'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.bjsxt.registration.action.UserAction] to required type [com.bjsxt.registration.model.User] for property 'user': no matching editors or conversion strategy found org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329) com.opensymphony.xwork2.spring.SpringObjectFactory.autoWireBean(SpringObjectFactory.java:182) com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:162) com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:133) com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139) com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109) com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
root cause
java.lang.IllegalArgumentException: Cannot convert value of type [com.bjsxt.registration.action.UserAction] to required type [com.bjsxt.registration.model.User] for property 'user': no matching editors or conversion strategy found org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231) org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138) org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329) com.opensymphony.xwork2.spring.SpringObjectFactory.autoWireBean(SpringObjectFactory.java:182) com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:162) com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:133) com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139) com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109) com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.
这个问题是我因为:struts2-spring-plugin在产生action的时候会自动注入action的属性,而我的action名字为user,而action的属性里面恰好也有一个user属性,所以自动注入的时候就出错了,把action的名字改掉,action注入时的bean的名字改掉,问题解决。