欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SSH整合异常:Unable to instantiate Action

程序员文章站 2022-06-05 14:22:20
...

今天在项目中遇到了

Unable to instantiate Action异常

异常的详细信息如下:

HTTP Status 500 - Unable to instantiate Action, com.syxp.yjxx.action.report.DisasterAction, defined for 'disasterReport_getTowerCodition' in namespace '/stormReport'Error creating bean with name 'com.syxp.yjxx.action.report.DisasterAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.syxp.yjxx.service.report.DisasterService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
Unable to instantiate Action, com.syxp.yjxx.action.report.DisasterAction,  defined for 'disasterReport_getTowerCodition' in namespace '/stormReport'Error creating bean with name 'com.syxp.yjxx.action.report.DisasterAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.syxp.yjxx.service.report.DisasterService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
	com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
	com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
	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:58)
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.syxp.yjxx.action.report.DisasterAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.syxp.yjxx.service.report.DisasterService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
	org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
	com.opensymphony.xwork2.spring.SpringObjectFactory.autoWireBean(SpringObjectFactory.java:193)
	com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:173)
	com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:144)
	com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
	com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120)
	com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
	com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
	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:58)
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.syxp.yjxx.service.report.DisasterService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
	org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
	org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
	org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
	org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:436)
	org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:414)
	org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:547)
	org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
	org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
	org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:302)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
	com.opensymphony.xwork2.spring.SpringObjectFactory.autoWireBean(SpringObjectFactory.java:193)
	com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:173)
	com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:144)
	com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
	com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120)
	com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
	com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
	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:58)
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

 异常原因分析:

在action中无法正确的实例化service类,导致实例化action失败。

异常的解决办法:

检查是否正确的导入了dao类,是否正确的导入了service类,即可解决。

我是因为忘记在service实现类中导入service接口造成