struts1.x+spring2.0中spring管理action的问题
我在使用spring来管理action的时候出现了一个奇怪的问题。在applicationContext.xml配置文件里面通过set方法为action注入一个类。在启动的时候报错:
[ERROR]main-org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/sshtest]-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 '/logon' defined in ServletContext resource [/WEB-INF/applicationContext-action.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [manager.UserManager] for property 'userManager'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [manager.UserManager] for property 'userManager': no matching editors or conversion strategy found
如果我在action类里面把需要注入的类换成接口的话就成功。这是为什么?
这是action的部分代码
public UserManager userManager;
//如果我在这把这个变量改成一个接口类型的就不会报错。???为什么呢?是因为spring托管action的时候在action里面只能注入接口?
public void setUserManager(UserManager userManager)
{
this.userManager = userManager;
}
struts配置文件
<action path="/logon"
type="org.springframework.web.struts.DelegatingActionProxy"
name="loginForm"
scope="request"
input="/index.jsp"
validate="true">
<forward name="success" path="/menu.jsp"/>
<forward name="failure" path="errorDef"/>
</action>
spring配置文件
<bean name="/logon" class="test.LoginAction">
<property name="userManager">
<ref bean="userManager"/>
</property>
</bean>