关于spring实例化action的注意事项

整合S2SH时做了个测试程序,总是报无法实例化Action的错误。郁闷。

测试部分代码是:

 ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

StudentAction students = new StudentAction();

students.leader();

运行时总是显示Action不能实例化,开始很郁闷。看配置什么的都没问题啊。最后发现用
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
StudentBean students = (StudentBean)ctx.getBean("studentBean");
students.findLeader();
就没有问题,郁闷中。。


后来发现应该是这样的。
Struts.xml中应该是这样:
<action name="loginAction" class="loginAction" >//此处的action class属性应该是applicationContext中spring实例化该action的 bean id 属性值。这样才是spring实例化的。
    <result name="leader">/Class_intro.jsp</result>
    <result name="cards">/Class_member.jsp</result>
   </action>


applicationContext.xml中:
<bean id="loginAction"
class="com.struts.action.StudentAction"
scope="prototype">
<property name="studentBean" ref="studentBean" />
</bean>

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值