View Javadoc
1   package org.springframework.cloud.client.serviceregistry;
2   
3   import org.springframework.beans.factory.annotation.Autowired;
4   import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
5   import org.springframework.context.annotation.Configuration;
6   import org.springframework.context.annotation.Import;
7   
8   import java.util.List;
9   
10  import javax.annotation.PostConstruct;
11  
12  /**
13   * in /META-INF/spring.factories
14   * see: {@link org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration}
15   *
16   * @author haolun zhang
17   */
18  @Configuration
19  @Import(AutoMultiServiceRegistrationConfiguration.class)
20  @ConditionalOnProperty(value = "spring.cloud.service-registry.auto-multi-registration.enabled", havingValue = "true")
21  public class AutoMultiServiceRegistrationAutoConfiguration {
22  
23      /**
24       * i.e. EurekaAutoServiceRegistration, ConsulAutoServiceRegistration ...
25       */
26      @Autowired(required = false)
27      private List<AutoServiceRegistration> autoServiceRegistrations;
28  
29      @Autowired
30      private AutoServiceRegistrationProperties properties;
31  
32      @PostConstruct
33      protected void init() {
34          if ((autoServiceRegistrations == null || autoServiceRegistrations.size() < 1) && this.properties.isFailFast()) {
35              throw new IllegalStateException("Auto Multi Service Registration has been requested, but there is no AutoServiceRegistration bean");
36          }
37      }
38  }