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

本文探讨了如何在Struts2中使用Spring进行依赖注入,包括配置方式及区别。介绍了如何将Action完全交由Spring管理,并说明了Struts2与Spring整合时自动注入的原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值