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 管理进行创建。
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 管理进行创建。
<action name="brand_*" class="aciton.BrandAction" method="{1}"/>
</package>你在这里写完整路径,就不要在spring里再写,这是由struts管理
你在spring里写了,这里的class就需要写那边bean的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>
<constant name="struts.objectFactory" value="spring" />
要放到最前面,以前没碰到这个问题
不过问题解决了,添加上scope = "prototype"就好了,谢谢各位!