Spring Boot: @TestConfiguration Not Overriding Bean During Integration Test

前端 未结 3 1832
感情败类
感情败类 2020-12-25 10:24

I have a Bean defined in a class decorated with @Configuration:

@Configuration
public class MyBeanConfig {

    @Bean
    public String configPa         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-25 11:17

    • Test configuration has to be explicitly imported in the test via @Import({MyTestConfiguration.class}).
    • The name of the @Bean methods in @Configuration and @TestConfiguration have to be different. At least it makes difference in Spring Boot v2.2.
    • Also make sure spring.main.allow-bean-definition-overriding=true otherwise the bean could not be overriden.

提交回复
热议问题