service类上要有标注,否则会报下面的错。缺少唯一的一个serivce bean。
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
Unable to instantiate Action, orgMgrAction, defined for ‘orgMgr‘ in namespace ‘/customer‘Error creating bean with name ‘orgMgrAction‘: Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.crm.service.personnel.PersonnelService org.crm.action.customer.orgMgrAction.personnelService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.crm.service.personnel.PersonnelService] is defined: Unsatisfied dependency of type [class org.crm.service.personnel.PersonnelService]: expected at least 1 matching bean com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:306) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:387) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘orgMgrAction‘: Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.crm.service.personnel.PersonnelService org.crm.action.customer.orgMgrAction.personnelService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.crm.service.personnel.PersonnelService] is defined: Unsatisfied dependency of type [class org.crm.service.personnel.PersonnelService]: expected at least 1 matching bean org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) java.security.AccessController.doPrivileged(Native Method)
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.crm.service.personnel.PersonnelService org.crm.action.customer.orgMgrAction.personnelService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No unique bean of type [org.crm.service.personnel.PersonnelService] is defined: Unsatisfied dependency of type [class org.crm.service.personnel.PersonnelService]: expected at least 1 matching bean
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:435)
org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)
org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.crm.service.personnel.PersonnelService] is defined: Unsatisfied dependency of type [class org.crm.service.personnel.PersonnelService]: expected
at least 1 matching bean
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:613)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor
解决办法: 在service类的前面加上标注。
@Service("personnelService")
@Transactional
public class PersonnelService {
。。。。。。。。
}