001/* 002 * Copyright 2012-2015 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.autoconfigure.cloud; 018 019import org.springframework.boot.autoconfigure.AutoConfigureOrder; 020import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 021import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 022import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 023import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 024import org.springframework.cloud.Cloud; 025import org.springframework.cloud.app.ApplicationInstanceInfo; 026import org.springframework.cloud.config.java.CloudScan; 027import org.springframework.cloud.config.java.CloudScanConfiguration; 028import org.springframework.context.annotation.Configuration; 029import org.springframework.context.annotation.Import; 030import org.springframework.context.annotation.Profile; 031import org.springframework.core.Ordered; 032 033/** 034 * {@link EnableAutoConfiguration Auto-configuration} for Spring Cloud. 035 * <p> 036 * Activates when there is no bean of type {@link Cloud} is configured in the context, the 037 * {@link Cloud} type (this spring-cloud) is on the classpath, and the "cloud" profile is 038 * active. 039 * <p> 040 * Once in effect, the auto-configuration is the equivalent of adding the 041 * {@link CloudScan} annotation in one of the configuration file. Specifically, it adds a 042 * bean for each service bound to the application and one for 043 * {@link ApplicationInstanceInfo} 044 * 045 * @author Ramnivas Laddad 046 * @since 1.2.0 047 */ 048@Configuration 049@Profile("cloud") 050@AutoConfigureOrder(CloudAutoConfiguration.ORDER) 051@ConditionalOnClass(CloudScanConfiguration.class) 052@ConditionalOnMissingBean(Cloud.class) 053@ConditionalOnProperty(prefix = "spring.cloud", name = "enabled", havingValue = "true", matchIfMissing = true) 054@Import(CloudScanConfiguration.class) 055public class CloudAutoConfiguration { 056 057 // Cloud configuration needs to happen early (before data, mongo etc.) 058 public static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 20; 059 060}