[英]Error in spring autowire annotation
嗨,我在应用程序中遇到以下错误,但无法解决:
ERROR localhost-startStop-1 org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'journeyHistoryCSVServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field:
com.common.application_service.impl.JourneyHistoryPrepareCSVServiceImpl com..common.application_service.impl.JourneyHistoryCSVServiceImpl.journeyHistoryPrepareCSVServiceImpl; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'journeyHistoryPrepareCSVServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.common.application_service.JourneyHistoryService com.common.application_service.impl.JourneyHistoryPrepareCSVServiceImpl.journeyHistoryService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'journeyHistoryServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.common.application_service.JourneyHistoryService com.common.application_service.impl.JourneyHistoryServiceImpl.journeyHistoryService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.common.application_service.JourneyHistoryService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
我的journeyHistoryCSVServiceImpl
是:
@Service("journeyHistoryCSVServiceImpl")
public class JourneyHistoryCSVServiceImpl implements JourneyHistoryCSVService {
static final Logger logger = LoggerFactory.getLogger(JourneyHistoryCSVServiceImpl.class);
@Autowired
protected JourneyHistoryPrepareCSVServiceImpl journeyHistoryPrepareCSVServiceImpl;
@Autowired
protected ApplicationContext applicationContext;
@Autowired
protected JourneyHistoryServiceImpl journeyHistoryServiceImpl;
我的JourneyHistoryPrepareCSVServiceImpl
是:
@Service("journeyHistoryPrepareCSVServiceImpl")
public class JourneyHistoryPrepareCSVServiceImpl extends AbstractBaseService implements JourneyHistoryPrepareCSVService {
static final Logger logger = LoggerFactory.getLogger(JourneyHistoryPrepareCSVServiceImpl.class);
@Autowired
protected JourneyHistoryService journeyHistoryService;
@Autowired
protected SystemParameterService systemParameterService;
更新:
您好仍然收到相同的错误:
@Service("journeyHistoryCSVServiceImpl")
public class JourneyHistoryCSVServiceImpl implements JourneyHistoryCSVService {
static final Logger logger = LoggerFactory.getLogger(JourneyHistoryCSVServiceImpl.class);
@Autowired
protected JourneyHistoryPrepareCSVServiceImpl journeyHistoryPrepareCSVServiceImpl;
@Autowired
protected ApplicationContext applicationContext;
@Autowired
protected JourneyHistoryService journeyHistoryService;
问题是,oyu尝试将bean连接到自身:
//remove those 2 lines
@Autowired
protected JourneyHistoryPrepareCSVServiceImpl journeyHistoryPrepareCSVServiceImpl;
你不需要这个
您在哪里定义了com.novacroft.nemo.tfl.common.application_service.JourneyHistoryService
类型的com.novacroft.nemo.tfl.common.application_service.JourneyHistoryService
?
仔细查看堆栈跟踪:)
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.novacroft.nemo.tfl.common.application_service.JourneyHistoryService] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.