package cn.muke.ssh.action; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import cn.muke.ssh.domain.Produce; import cn.muke.ssh.service.ProduceService; public class Produceaction extends ActionSupport implements ModelDriven<Produce> { private Produce produce = new Produce(); @Override public Produce getModel() { // TODO Auto-generated method stub return produce; } private ProduceService produceService; public void setProduceService(ProduceService produceService) { this.produceService = produceService; } public String save(){ System.out.println("save"); produceService.save(produce); return NONE; } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="produceService" class="cn.muke.ssh.service.ProduceService"> <property name="dao" ref="dao"></property> </bean> <bean id="dao" class="cn.muke.ssh.dao.ProduceDao"> </bean> </beans>
我看到的是别人回答的导入struts2-spring-plugin包,我之前导入的是最新的jar包,struts2-spring-plugin-2.3.34一直出现这个问题,后来重新导入struts2-spring-plugin-2.3.15.2就没问题了,大家可以试试。终于解决了
忘了怎么解决了,尽量规范命名bean的id吧,比如类名为ProduceDao,id就为produceDao
<bean id="produceDao" class="cn.muke.ssh.dao.ProduceDao">
</bean>
我也遇到了,本来以为页面输入数据可能会自动传到后台。。没想到还是报空指针(主要是针对Product)。。。能解答下吗???
我也遇到这个问题了,有人解答下吗
null调用方法的时候就会报空指针异常