Unable to instantiate Action, cn.star.ssh.action.ProductAction, defined for 'product_save' in namespace '/'null
我换成jdk1.6也没用,用老师的第二种方法就没问题了
明明昨天用jdk1.8还好好的,今天就出问题了
出现这种问的童鞋,jdk换到1.6就行了,要用1.8的话,spring要用4
// Struts和Spring整合过程中按名称自动注入业务层的类
private ProductService productService;
public void setProductService(ProductService productService) {
this.productService = productService;
}
感觉是这句话没有起作用
可是jar包已经导入了啊
package cn.star.ssh.action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import cn.star.ssh.entity.Product;
import cn.star.ssh.service.ProductService;
/**
* 商品管理的Action的类
*/
public class ProductAction extends ActionSupport implements ModelDriven<Product>{
/**
*
*/
private static final long serialVersionUID = 1L;
// 模型驱动使用的类
private Product product = new Product();
@Override
public Product getModel() {
return product;
}
// Struts和Spring整合过程中按名称自动注入业务层的类
private ProductService productService;
public void setProductService(ProductService productService) {
this.productService = productService;
}
/**
* 保存商品的执行的方法:save
*/
public String save(){
System.out.println("Action中的save方法执行了...");
productService.save(product);
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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd">
<!-- 配置业务层的类 -->
<bean id="productService" class="cn.star.ssh.service.ProductService">
<property name="productDao" ref="productDao"></property>
</bean>
<!-- 配置DAO的类 -->
<bean id="productDao" class="cn.star.ssh.dao.ProductDao">
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- Struts2配置 -->
<struts>
<package name="ssh" extends="struts-default" namespace="/">
<action name="product_save" class="cn.star.ssh.action.ProductAction" method="save">
</action>
</package>
</struts>