迁移到Spring Boot 2.1.7之后,RELEASE-initializeBean不起作用

问题描述 投票:0回答:1

在将spring4.1.7迁移到spring boot2.1.7 Release之后。它在初始化应用程序上下文时显示Bean创建错误。

错误日志

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'localConfig' available
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:771)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307)
    ... 25 more

ServiceConfiguration类

@Configuration
@Profile(ContextProfileNames.SERVICE)
@EnableWebMvc
@ComponentScan(basePackages = "com.get.services")
@Import(ControllerConfiguration.class)
public class ServiceConfiguration implements InitializingBean
{

    @Autowired
    private ApplicationContext context;

    @Bean(name = "localConfig")
    @DependsOn(BeanNames.CONFIGURATION_FACTORY)
    @Scope("singleton")
    public LocalDataSourceConfiguration getLocalDataSourceConfiguration() throws XEDecryptionException
    {
        ConfigurationFactory configurationFactory = (ConfigurationFactory) context
                .getBean(BeanNames.CONFIGURATION_FACTORY);
        LocalDataSourceConfig localDataSourceConfig = configurationFactory.getLocalDataSourceConfiguration();

        LocalDataSourceConfiguration localDataSourceConfiguration = new LocalDataSourceConfiguration(
                localDataSourceConfig.isMsSqlConfigured(), localDataSourceConfig.isSybaseConfigured(),
                localDataSourceConfig.getServiceConfigurationMode(), getLocalDBConfigurationInfo(
                        localDataSourceConfig.getDbConfigurations().getDbConfigInfo(), configurationFactory));
        localDataSourceConfiguration
                .setUseRisExamIdAsAccession(Boolean.parseBoolean(localDataSourceConfig.getUseRisExamIdAsAccession()));
        localDataSourceConfiguration.setCpacsNameFormat(localDataSourceConfig.getCpacsNameFormat());
        localDataSourceConfiguration.setTableCacheRefreshInterval(localDataSourceConfig.getTableCacheRefreshInterval());
        localDataSourceConfiguration.setAuthorityMatchingMode(localDataSourceConfig.getAuthorityMatchingMode());
        return localDataSourceConfiguration;
    }
 }

我该如何解决这个问题?我错过了什么吗?

spring spring-boot spring-mvc
1个回答
0
投票

在主类中添加了@profile。问题已解决

© www.soinside.com 2019 - 2024. All rights reserved.