struts整合spring,action中用spring注入时,hibernateTemplate空指针

来源:互联网 发布:学校软件 编辑:程序博客网 时间:2024/06/07 21:26

1.如果在测试类中用ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");就可以通过;另一种是用Spring的提供的测试方法就可以通过,不会报空了



2.当没有加入spring中common-annotations.jar时,也可能导致action不能被spring注入,

3.当applicationContext.xml中没有配置:<context:component-scan base-package="cw.ok" />让spring自动去扫描管理那些组件;这个没配好,也可能会出现,奇怪的异常;


4.当整合了SSH框架后,在Struts2的action中,若不用spring注解,action会帮你自动注入到spring中;当想使用spring注解action的时候,要注意不要忘记写:@Scope("prototype"),同时在struts的配置文件struts.xml中配置action标签时,class应该和注解取的名称一致:如class="user" ;action中spring的注解:@Component("user") ;