我正在尝试实现我的集成测试。我的应用程序实现如下:
@SpringBootApplication
@ComponentScan(basePackages = ["com.lib"])
class Application
字符串
在com.lib中,有一个@Configuration类调用SystemConfig
,它有一个标记为@Primary的@Bean,我想用MyConfig
类覆盖它,所以我实现了我的ApplicationTest,如下所示:
@SpringBootTest
@ContextConfiguration(classes = [Application::class, MyConfig::class])
class ApplicationTest
型
我一直在尝试使用所有的方式这个链接建议https://www.baeldung.com/spring-boot-exclude-auto-configuration-test例如添加
@EnableAutoConfiguration(exclude=SystemConfig.class)
@SpringBootTest
@ContextConfiguration(classes = [Application::class, MyConfig::class])
class ApplicationTest
型
如果我在MyConfig
中将@Bean标记为@Primary,那么它将有多个@Primary bean。
考虑使用@Profile,但SystemConfig来自外部库,所以我不能修改它。
1条答案
按热度按时间pxy2qtax1#
我认为使用
@Profile
是一个很好的选择,即使使用第三方库也可以使用配置文件解决这个问题。试试这个:
字符串
为测试创建自定义配置
型