ssh中访问Action时报错Unable to instantiate Action,Initialization of bean failed, nested exception is xx

[JAVA-JSP-SSH]调试一个SSH小项目,给它添加一个Action,在页面中异步访问时,居然一直访问不了,页面没有异常信息,eclipse控制台也不见有错误信息,查看启动信息,发现Action也已经被spring托管到了。

---------spring-bean.xml 配置没问题------
<bean id="cangkuBiz" class="com.cxstock.biz.ziliao.imp.CangkuBizImpl">
<property name="baseDao" ref="baseDao"/>
</bean>
<bean id="cangkuAction" class="com.cxstock.action.ziliao.CangkuAction" scope="prototype">
<property name="cangkuBiz" ref="cangkuBiz"/>
</bean>
---------------------------------
----------struts.xml 配置也没问题-------------
<package name="main" extends="cxstock" namespace="/">
<action name="*_*" class="{1}Action" method="{2}">
<result name="input">/login.jsp</result>
<result name="success" type="redirect">/jsp/main/index.jsp</result>
<interceptor-ref name="loginedCheck" /> 
<interceptor-ref name="defaultStack" />
</action>
</package>

------------------------------------------

后来直接把访问地址放到地址栏测试

http://localhost/项目名/cangku_findAllCangku.do

终于在页面看到了异常信息:

HTTP Status 500 - Unable to instantiate Action, cangkuAction, defined for 'cangku_findAllCangku' in namespace '/'Error creating bean with name 'cangkuAction' defined in file [D:\JAVAtest\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyStock\WEB-INF\classes\spring-bean.xml]: Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'cangkuBiz' of bean class [com.cxstock.action.ziliao.CangkuAction]: No property 'cangkuBiz' found

-----百度了一下,很快找到原因-------CangkuAction.java 中漏写了cangkuAction的ref="cangkuBiz"-----------
private CangkuBiz cangkuBiz;//添加这个ref
//必须要有set方法,否则spring获取bean时找不到cangkuBiz
public void setCangkuBiz(CangkuBiz cangkuBiz) {
this.cangkuBiz = cangkuBiz;
}
------------------------------------

参考https://blog.csdn.net/tqwwilliam/article/details/7315741

----------------总结----------------

 正常方式访问,如果eclipse控制台没有错误信息,页面也没有,就把访问action的url单独拿出来测试(如果有500拦截页面的要先取消),让异常信息显示出来,就方便找到原因了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值