mercyblitz 6 years ago
parent edb9d56dc4
commit f34633ebf4

@ -19,7 +19,6 @@ package org.springframework.cloud.alibaba.nacos;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.alibaba.nacos.registry.NacosAutoServiceRegistration; import org.springframework.cloud.alibaba.nacos.registry.NacosAutoServiceRegistration;
@ -34,38 +33,37 @@ import org.springframework.context.annotation.Configuration;
/** /**
* @author xiaojing * @author xiaojing
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/ */
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@ConditionalOnNacosDiscoveryEnabled @ConditionalOnNacosDiscoveryEnabled
@ConditionalOnClass(name = "org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent")
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
@AutoConfigureBefore({ AutoServiceRegistrationAutoConfiguration.class, @AutoConfigureBefore({AutoServiceRegistrationAutoConfiguration.class,
NacosDiscoveryClientAutoConfiguration.class }) NacosDiscoveryClientAutoConfiguration.class})
@AutoConfigureAfter(AutoServiceRegistrationConfiguration.class) @AutoConfigureAfter(AutoServiceRegistrationConfiguration.class)
public class NacosDiscoveryAutoConfiguration { public class NacosDiscoveryAutoConfiguration {
@Bean @Bean
public NacosServiceRegistry nacosServiceRegistry() { public NacosServiceRegistry nacosServiceRegistry() {
return new NacosServiceRegistry(); return new NacosServiceRegistry();
} }
@Bean @Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class) @ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosRegistration nacosRegistration( public NacosRegistration nacosRegistration(
NacosDiscoveryProperties nacosDiscoveryProperties, NacosDiscoveryProperties nacosDiscoveryProperties,
ApplicationContext context) { ApplicationContext context) {
return new NacosRegistration(nacosDiscoveryProperties, context); return new NacosRegistration(nacosDiscoveryProperties, context);
} }
@Bean @Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class) @ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosAutoServiceRegistration nacosAutoServiceRegistration( public NacosAutoServiceRegistration nacosAutoServiceRegistration(
NacosServiceRegistry registry, NacosServiceRegistry registry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties, AutoServiceRegistrationProperties autoServiceRegistrationProperties,
NacosRegistration registration) { NacosRegistration registration) {
return new NacosAutoServiceRegistration(registry, return new NacosAutoServiceRegistration(registry,
autoServiceRegistrationProperties, registration); autoServiceRegistrationProperties, registration);
} }
} }
Loading…
Cancel
Save