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

这个问题是看马士兵的视频想到的,其实在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文件里面的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值