如何在 SpringBoot 3.x 应用程序中使用第三方库中定义的 void 返回类型的@Bean

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

我的 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 方应用程序内进行更改,请指导我如何克服这个问题。

java spring spring-boot javabeans
1个回答
0
投票
不支持返回

@Bean

 的方法。如果您无法更改第三方代码,那么您可以排除 Configuration 类并自行定义 bean。
不要通过 
void

包含第三方 bean 类,而是使用

scanBasePackages

,并排除 Config 类
@ComponentScan


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