struts1.x+spring2.0中spring管理action的问题

userdaye 2008-11-19 10:39:40
我在使用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>
...全文
371 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
at1943 2010-08-15
  • 打赏
  • 举报
回复
applicationcontext中userManager这个对象是使用接口实例化的。
userdaye 2008-11-21
  • 打赏
  • 举报
回复
去掉了也不行的。我在spring文件里面加了事务配置。如果去掉事务管理就可以,不知道是为什么,高手帮帮忙。。。
laitaogood 2008-11-20
  • 打赏
  • 举报
回复
去掉type属性
type="org.springframework.web.struts.DelegatingActionProxy"

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧