1.在pom.xml中增長applo的相關依賴redis
<!-- 配置中心 --> <dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>0.10.2</version> </dependency>
META-INF中建立app.properties配置文件spring
2.把config.properties中的配置文件增長到applo中tomcat
直接把配置文件放到applo中,很簡單他會本身增長對應的格式app
增長完成後,把本地的config.properties註釋掉3d
3.xml
a、頭文件中添加apolloblog
xmlns:apollo="http://www.ctrip.com/schema/apollo" http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd
b、PreferencesPlaceholderConfigurer替換成PropertySourcesPlaceholderConfigurerip
<bean id="propertyConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"> <property name="properties" ref="configProperties" /> <property name="ignoreUnresolvablePlaceholders" value="true"/> </bean>
四、應用啓動入口Setup中添加啓動註解io
包 :import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;class
@org.springframework.context.annotation.Configuration @EnableApolloConfig(value = "application", order = 10)
五、配置文件中使用apollo配置
a、數據源配置文件database.xml
b、redis配置文件jedis.xml
c、等等,其餘須要apollo配置的文件
格式:${鍵:默認值} 若是阿波羅apollo配置不可用,使用默認值
六、項目啓動
tomcat中增長啓動參數
-Denv=DEV -Dapollo.autoUpdateInjectedSpringProperties=true -Ddev_meta=http://端口號 -Dfile.encoding=UTF-8