spring+struts2整合后的空指针异常:
今天将s2sh三个框架整合在了一起,并且做了个简单的查询功能,在我的web project工程中我分为三次 ACTION、SERVICE、DAO。
并且做好了注入。
<!-- dao层注入sessionFactory -->
<bean id="couDAO" class="com.esoft.jeescs.dao.impl.FindCourseDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- service层注入dao -->
<bean id="findCourseServiceImpl" class="com.esoft.jeescs.service.impl.FindCourseServiceImpl">
<property name="findCourseDao">
<ref bean="couDAO" />
</property>
</bean>
<!-- action层注入service -->
<bean id="findMysql" class="com.esoft.jeescs.action.FindMysql">
<property name="findCourseService">
<ref bean="findCourseServiceImpl" />
</property>
</bean>
启动项目没问题,然后触发功能是,抛出一个异常
java.lang.NullPointerException
com.esoft.jeescs.action.FindMysql.findCourse(FindMysql.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
可以看出是我们action层没有注入成功。
在网上查询了许久,发现时我的struts.xml文件配置存在了问题。在配置文件中class必须要和spring配置文件中的ID对应上,这样才可以
<action name="findMysql" class="findMysql" method="findCourse">
<result name="success">/login.jsp</result>
<result name="error">/login.jsp</result>
</action>
我印象中好像struts的class配置直接对应到类的路径也行,但是忘记要做什么其他的配置了,待后续查找下原因吧。
如果有大神知道可以告知下