SpringBoot调整Configuration的执行顺序

有的时候,SpringBoot中会发现Configuration的执行顺序不是我们想要的,可以修正这个顺序,如下:

@Configuration
@AutoConfigureBefore(BConfiguration.class)
public class AConfiguration {

    @Bean
    @ConditionalOnMissingBean(XXX.class)
    public XXX XXX() {
        return new XXX();
    }

    @Bean
    @ConditionalOnMissingBean(YYY.class)
    public YYY YYY() {
        return new YYY();
    }

}

这样搞完后,A会先执行,然后才是B

3 thoughts on “SpringBoot调整Configuration的执行顺序

Leave a Reply

Your email address will not be published.