您的位置:首页 > 编程语言 > Java开发

struts2和spring结合时,action的class属性应该写什么

2010-12-25 21:19 429 查看
这个问题是看马士兵的视频想到的,其实在Struts 2 Documentation里面已经规定的很清楚了。

Normally, in struts.xml you specify the class for each Action. When using the default SpringObjectFactory, the framework will ask Spring to create the Action and wire up dependencies as specified by the default auto-wire behavior.

也就是说,你class指定的是真正的class 也就是com.my.*这种的话那就是 wire up dependencies as specified by the default auto-wire behavior,就是自动注入action里面的属性,默认是by name。

you might want the bean to be completely managed by Spring.如果要完全的将action交给spring管理,那么all you have to do is configure the bean in your Spring applicationContext.xml and then change the class attribute from your Action in the struts.xml to use the bean name defined in Spring instead of the class name.

只要把class属性的名字写成bean的名字。

这样经过我测试就不会自动注入,原因的话我想是struts在这已经对action完全失去控制,也就不会让spring给你注入了,因为

struts.objectFactory.spring.autoWire的属性是写在struts2-spring-plugin-2.jar这个里面的struts-plugin.xml文件里面的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: