SpringBoot自动化装配中,如果有两个AutoConfiguration,A依赖B,这时ConditionalOnBean如何保证顺序使需要的Bean会提前加载
使用@AutoConfigureAfter, 当几个组件加载完成后,再加载当前组件,如:Nacos服务注册自动配置类加载前需要加载:通用的服务注册配置,服务注册的自动化配置,服务发现的自动化配置;
@Configuration( proxyBeanMethods = false ) @EnableConfigurationProperties @ConditionalOnNacosDiscoveryEnabled @ConditionalOnProperty( value = {"spring.cloud.service-registry.auto-registration.enabled"}, matchIfMissing = true ) @AutoConfigureAfter({AutoServiceRegistrationConfiguration.class, AutoServiceRegistrationAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class}) public class NacosServiceRegistryAutoConfiguration { ...... }
标签:装配,SpringBoot,自动化,组件,class,加载 From: https://www.cnblogs.com/yifanSJ/p/17575698.html