Spring Boot: @TestConfiguration Not Overriding Bean During Integration Test

前端 未结 3 1823
感情败类
感情败类 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:10

    Make sure that the method name of your @Bean factory method does not match any existing bean name. I had issues with method names like config() or (in my case) prometheusConfig() which collided with existing bean names. Spring skips those factory methods silently and simply does not call them / does not instantiate the beans.

    If you want to override a bean definition in your test, use the bean name explicitly as string parameter in your @Bean("beanName") annotation.

提交回复
热议问题