本帖最后由 wctor 于 2012-11-06 09:55:56 编辑

解决方案 »

  1.   

     Error creating bean with name 'brandAction' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is 
    org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [?? 后面这一截 会显示出创建的那个bean出错 你没有截图出来 所以我不知道到底初始化那个bean的时候就报错了。注:提议一点 spring有强大的bean容器管理 
    <action name="brand_*" class="aciton.BrandAction" method="{1}"/>
    struts这里的action 应采用spring 代理类 交于spring 管理进行创建。
      

  2.   

    <package name="default" namespace="/" extends="struts-default">
            <action name="brand_*" class="aciton.BrandAction" method="{1}"/>
        </package>你在这里写完整路径,就不要在spring里再写,这是由struts管理
    你在spring里写了,这里的class就需要写那边bean的id
      

  3.   

    二楼已经告诉楼主了,struts.xml中的class属性应配置spring中定义的id的名字
    在项目中你已经加入了struts和spring的整合的jar包:struts2-spring-plugin-2.3.4.1.jar,那么struts中的action的创建就会由spring来负责实例化,你在struts.xml中写的是:<package name="default" namespace="/" extends="struts-default">
            <action name="brand_*" class="aciton.BrandAction" method="{1}"/>
    </package>那么就会在spring中找id为"action.BrandAction"的一个类,但是它没有找到,所以就实例化失败了,这么地方的class属性值应该配置为brandAction另外,在你的applicationContext.xml文件中配置的action应该配置它的scope为prototype,因为它默认是single,这样就不对了,即改为:
    <bean id="brandAction" class="action.BrandAction" scope="prototype"></bean>
      

  4.   

    不好意思,写错了一个地方,scope的默认值应为singleton,上面写错了
      

  5.   

    是不是这一句:
    <constant name="struts.objectFactory" value="spring" />
    要放到最前面,以前没碰到这个问题
      

  6.   

    1楼、2楼和3楼,不好意思,我贴struts配置文件的时候贴错了,因为spring里bean action不行,所以我就把struts里配置文件里的action改成真实路径用ClassPathXmlApplicationContext()获取过来让代码正常运行了。事实上struts配置文件里写的是bean的id。
    不过问题解决了,添加上scope = "prototype"就好了,谢谢各位!