我的 SpringBoot 3.X 应用程序正在使用第 3 方库(依赖项),该库在
@Configuration
类中定义了一个 @Bean,如下所示:
@Bean
public void performUpdateForAllInstances() throws Exception {....}
我正在使用
@SpringBootApplication(scanBasePackages = "package.path.from.third.party.*")
扫描配置。
启动应用程序时,我收到以下错误:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Bean method 'performUpdateForAllInstances' must not be declared as void; change the method's return type or its annotation.
相同的依赖关系在使用 SpringBoot 2.X 的旧应用程序中运行良好
我无法在第 3 方应用程序内进行更改,请指导我如何克服这个问题。
@Bean
的方法。如果您无法更改第三方代码,那么您可以排除 Configuration 类并自行定义 bean。
不要通过
void
包含第三方 bean 类,而是使用 scanBasePackages
,并排除 Config 类
@ComponentScan