when i test the parameterizedContainer annotation parameter on overloading @Bean method. found that the first bean method init more than once,but another never init。 code like this:

/**
 * @author zhangxm
 * @date 2020-01-17
 */
@Configuration
public class ConditionOnBeanTest {

    @Bean(name = "testBean1")
    @ConditionalOnBean(parameterizedContainer = {List.class})
    public List<ConditionOnBeanTest> testBean(int intParameterTest, long longParameterTest) {
        System.out.println("testListStringBean -- intParameterTest");
        return Collections.singletonList(new ConditionOnBeanTest());
    }

    @Bean(name = "testBean2")
    @ConditionalOnBean(parameterizedContainer = {List.class})
    public List<ConditionOnBeanTest> testBean(String stringParameterTest) {
        System.out.println("testListStringBean -- stringParameterTest");
        return Collections.singletonList(new ConditionOnBeanTest());
    }

    @Bean
    public String testStringBean() {
        System.out.println("testStringBean");
        return "testStringBean";
    }

    @Bean
    public int testIntBean() {
        System.out.println("testIntBean");
        return 812;
    }

    @Bean
    public long testLongBean() {
        System.out.println("testLongBean");
        return 8120L;
    }

}

Comment From: philwebb

As mentioned in the Javadoc you should only use @ConditionOnBean for auto-configuration classes. Furthermore, it doesn't really make sense to try and use it within the context of a single configuration class.