在action中调用去出现java.lang.NullPointerException错误

时间:2021-12-04 21:12:13
struts.xml ,中实例化了action ,<action name="adduser" class="com.jsw.struts2.action.UserAction">  

而在spring 中也实例了action,这样实例化对象无法setter ,出现null ,

<bean id="UserAction" class="com.jsw.struts2.action.UserAction">
<property name="userservice" ref="UserService"/>
</bean>

不妨修改为

struts.xml

<action name="adduser" class="这里就是spring 注册的action bean 的id">

eg:<action name="adduser" class="UserAction">



spring.xml

<bean id="UserAction" class="com.jsw.struts2.action.UserAction" scope="prototype">
  <property name="userservice" ref="UserService"/>
</bean>