首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-09-19 
spring struts2整合之action 产生问题 service 为null?Service层: 定义接口WposService和接口的实现类Wpos

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来管理的。

?

热点排行