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

时间:2019-09-24 12:08:09

标签: spring spring-boot spring-mvc

将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;
    }
 }

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

1 个答案:

答案 0 :(得分:1)

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