当前位置: 代码迷 >> Web前端 >> 8、Unable to instantiate Action, xxx.action.DeleteAction, defined for 'delete' in namespace
  详细解决方案

8、Unable to instantiate Action, xxx.action.DeleteAction, defined for 'delete' in namespace

热度:1452   发布时间:2013-09-11 17:59:59.0
八、Unable to instantiate Action, xxx.action.DeleteAction, defined for 'delete' in namespace
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

Unable to instantiate Action, xxx.action.DeleteAction,  defined for 'delete' in namespace '/'Error creating bean with name 'serviceDao' defined in class path resource [ssh.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
	com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:307)
	com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
	org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
	org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
	com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

root cause

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceDao' defined in class path resource [ssh.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	java.security.AccessController.doPrivileged(Native Method)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:1029)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:977)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329)
	com.opensymphony.xwork2.spring.SpringObjectFactory.autoWireBean(SpringObjectFactory.java:182)
	com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:162)
	com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:133)
	com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139)
	com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109)
	com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288)
	com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
	org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
	org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
	com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

root cause

java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
	org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:117)
	org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	java.security.AccessController.doPrivileged(Native Method)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:1029)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:977)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329)
	com.opensymphony.xwork2.spring.SpringObjectFactory.autoWireBean(SpringObjectFactory.java:182)
	com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:162)
	com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:133)
	com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139)
	com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109)
	com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288)
	com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
	org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
	org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
	com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
Apache Tomcat/6.0.20

原因:

ssh.xml的配置文件如下:

<bean id="orderDao" class="xxx.impl.HibernateOrderDAO">
          <property name="sessionFactory" ref="hsFactory"></property>
      </bean>
      <bean id="itemDao" class="xxx.impl.HibernateItemDAO">
          <property name="sessionFactory" ref="hsFactory"></property>
      </bean>
      
      <bean id="serviceDao" class="xxx.impl.HibernateServiceDAO">
            <property name="orderDAO" ref="orderDao"></property>
            <property name="itemDAO" ref="itemDao"></property>
      </bean>

而定义ServiceDAO的实现类时,继承了HibernateDaoSupport,就必须使用  <property name="sessionFactory" ref="hsFactory"></property>
public class HibernateServiceDAO
        extends HibernateDaoSupport implements ServiceDAO {....... }

但serviceDao组件只是引用了orderDao和itemDao,所以不需要继承HibernateDaoSupport


解决:

将public class HibernateServiceDAO
        extends HibernateDaoSupport implements ServiceDAO {....... }

修改为:

public class HibernateServiceDAO  implements ServiceDAO {....... }


我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
  相关解决方案