最近一段时间在研究struts2-spring3.X-hibernate
看完书后自己重写了一遍书中的系统
struts2.xml 和 applicationContext.xml文件使用myEclipse默认生成的文件
系统采用贫血模式,分为三层:
model层: 使用myEclipse中的映射向导生成表中的映射文件
Dao层: 封装model层,并提供相应的增删改查方法
Service层: 封装Dao层,提供对外调用的方法
Action包里是页面调用各个Action类及方法
问题:
struts2.xml 和 applicationContext.xml文件配置配置完成,服务正常启动, 弱不调用
Service层中的方法,页面跳转、session的写入和输出均正常。
一旦调用Service中的方法,系统就会包空指针错误
解决方法:引入jar包, 我使用的是 struts2-spring-plugin-2.3.4.jar
注:struts2.xml也要交由spring管理, 只需在struts2.xml文件如下标签即可
<beans>
<!-- struts交给spring管理 -->
<constant name="struts.objectFactoy" value="spring"/>
<pakcage...>
...
</package>
</beans>