问答详情
源自:4-3 配置Action,Service,Dao的类-Struts2整合Spring

无法实例化的行动,cn.star.ssh.action.productaction

Unable to instantiate Action, cn.star.ssh.action.ProductAction, defined for 'product_save' in namespace '/'null

提问者:FloatingShuYin 2016-10-11 15:59

个回答

  • chendaniu
    2018-09-18 22:13:20

    我换成jdk1.6也没用,用老师的第二种方法就没问题了

  • 慕丝9008190
    2017-08-12 09:39:58

    明明昨天用jdk1.8还好好的,今天就出问题了

  • 小小菜鸟lee
    2016-10-21 11:24:54

    出现这种问的童鞋,jdk换到1.6就行了,要用1.8的话,spring要用4

  • FloatingShuYin
    2016-10-11 16:14:00

    // Struts和Spring整合过程中按名称自动注入业务层的类

    private ProductService productService;


    public void setProductService(ProductService productService) {

    this.productService = productService;

    }

    感觉是这句话没有起作用

    http://img.mukewang.com/57fc9f2f0001bbe602360067.jpg

    可是jar包已经导入了啊

  • FloatingShuYin
    2016-10-11 16:09:26

    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;

    }

    }


  • FloatingShuYin
    2016-10-11 16:03:18

    没搞懂哪里错了 

  • FloatingShuYin
    2016-10-11 16:01:00

    <?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>


  • FloatingShuYin
    2016-10-11 16:00:37

    <?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>