读书人

spring struts2整合之action 产生有关

发布时间: 2012-09-19 13:43:54 作者: rapoo

spring struts2整合之action 产生问题 service 为null

?

Service层: 定义接口WposService和接口的实现类WposServiceImpl

?

Action层:

?

? ? WposAction.java的内容:

?

?

Structs2的struts.xml配置

?

?

?

问题如下:

? ? 1、applicationContext.xml中 ?property name="wposSer",是实际存在的id为wposSer的bean

?

? ? 因为Structs2的struts.xml中action的class路径不是Spring中配置的action的id,而是类的全路径,这样工程启动时action的控制权由structs掌管,当我们访问Action的时候首先由struts创建Action,然后在跟据Action的属性 wposSer去spring容器中去找id为wposSer的bean,如果不存在bean的id为wposSer(绿色标注),报空指针异常,wposSer为空。

?

? ? 2、WposAction中必须有spring中bean的id为property属性,并写好getter(),setter()方法,否则报org.springframework.beans.NotWritablePropertyException异常

?

? ? 3、可以把struts中action的class设置为spring容器中的bean的id时,action的创建及属性注入式有spring来管理的。

?

读书人网 >编程

热点推荐