迁移到Spring Boot 2.1.7版本后,释放初始化项Bean not working
在将spring4.1.7迁移到SpringBoot2.1.7发行版之后。在初始化应用程序上下文时显示了创建bean的错误 错误日志迁移到Spring Boot 2.1.7版本后,释放初始化项Bean not working,spring,spring-boot,spring-mvc,Spring,Spring Boot,Spring Mvc,在将spring4.1.7迁移到SpringBoot2.1.7发行版之后。在初始化应用程序上下文时显示了创建bean的错误 错误日志 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'localConfig' available at org.springframework.beans.factory.support.DefaultListableBeanF
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
服务配置类
@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;
}
}
如何解决此问题?我是否遗漏了任何内容?在主类中添加了@profile。问题已解决您的配置取决于配置文件和可用的bean,请确保您启用了该配置文件,并且另一个bean可用。另外,我强烈建议不要使用
@DependsOn
,而是直接将依赖关系注入getLocalDataSourceConfiguration
。这将为您节省一次查找(并输入ApplicationContext
)和@DependsOn
,因为Spring现在可以自己解决这个问题。最后请注意,升级到SpringBoot2.1,您正在升级(并跳过)Spring的4个版本!这可能也需要一些注意!。