struts2 与struts1和Spring整合时Bean的配置区别

来源:互联网 发布:傲剑狮子上豹子数据 编辑:程序博客网 时间:2024/04/29 15:19


在STRUTS1中需要自己声明属性即你写的

<property name="itemService" ref="itemService"/>
而在STRUTS2中这个完全被框架实现了,你所要做的
只是在UserAction里声明类对象
private UserService uservice;
实现GET 和SET

就可以直接用了,具体注入,由框架自己进行!


在struts1的可以这样配置:
<bean name="/item" class="com.blog.web.actions.ItemAction">
<property name="itemService" ref="itemService"/>
<property name="dataDictService" ref="dataDictService"/>
</bean>


在struts2则只需要在ItemAction中定义

private ItemService itemService;

private DataDictService dataDictService;

并实现相应的GET和SET即可,不需要在applicationContext中再action的bean配置

但要注意:struts2的action中定义的Service实例名必须与applicationContext中定义的Service的bean id名一致,否则action中的Service instance会初始化失败,调用时会抛出空指针的错误


原创粉丝点击