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

来源:4-3 配置Action,Service,Dao的类-Struts2整合Spring

FloatingShuYin

2016-10-11 15:59

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

写回答 关注

8回答

  • 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

    慕粉3988...

    强! 同问:为什么?

    2016-12-22 10:43:57

    共 3 条回复 >

  • 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包已经导入了啊

    Night离

    重新放到lib目录下试试

    2017-03-01 17:35:21

    共 1 条回复 >

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


基于SSH实现员工管理系统之框架整合篇

本视频教程主要介绍环境搭建和SSH框架整合,逐层深入理解学习

49831 学习 · 344 问题

查看课程

相似问题