gpt4 book ai didi

java - spring Autowiring 注释错误

转载 作者:太空宇宙 更新时间:2023-11-04 15:20:28 25 4
gpt4 key购买 nike

您好,我在我的应用程序中收到以下错误,但无法解决它:

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;

最佳答案

问题是,您尝试将 bean 连接到自身:

//remove those 2 lines
@Autowired
protected JourneyHistoryPrepareCSVServiceImpl journeyHistoryPrepareCSVServiceImpl;

你不需要这个

关于java - spring Autowiring 注释错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20446222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com