框架技术--S2SH框架整合(异常)No 1

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配置直接对应到类的路径也行,但是忘记要做什么其他的配置了,待后续查找下原因吧。

如果有大神知道可以告知下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值