Spring boot not complaining about two beans with the same name

后端 未结 2 1538
情书的邮戳
情书的邮戳 2021-02-20 12:22

I\'m having the following configuration where I have two Spring beans with the same name from two different configuration classes.

import org.springframework.con         


        
2条回答
  •  無奈伤痛
    2021-02-20 13:18

    You need to name that beans so:

    @Configuration
    public class RestTemplateConfiguration {
    
        @Bean(name="bean1")
        public RestTemplate restTemplate() {
            return new RestTemplate();
        }
    }
    

    And

    @Configuration 
    public class OtherRestTemplateConfiguration {
    
        @Bean(name="bean2")
        public RestTemplate restTemplate() {
            return new RestTemplate();
        }
    }
    

提交回复
热议问题