程序员的资源宝库

网站首页 > gitee 正文

项目中增加集中配置管理-appllo 集中配置中心

sanyeah 2024-03-29 17:44:02 gitee 8 ℃ 0 评论

1.在pom.xml中增加applo的相关依赖

         <!-- 配置中心 -->
		<dependency>
			<groupId>com.ctrip.framework.apollo</groupId>
			<artifactId>apollo-client</artifactId>
			<version>0.10.2</version>
		</dependency>

 META-INF中创建app.properties配置文件

 

2.把config.properties中的配置文件增加到applo中

直接把配置文件放到applo中,很简单他会自己增加对应的格式

增加完成后,把本地的config.properties注释掉

3.

a、头文件中添加apollo

xmlns:apollo="http://www.ctrip.com/schema/apollo"
http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd

 

b、PreferencesPlaceholderConfigurer替换成PropertySourcesPlaceholderConfigurer

<bean id="propertyConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
		<property name="properties" ref="configProperties" />
		<property name="ignoreUnresolvablePlaceholders" value="true"/>
	</bean>

 4、应用启动入口Setup中添加启动注解

 

 包 :import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;

@org.springframework.context.annotation.Configuration
@EnableApolloConfig(value = "application", order = 10)

 5、配置文件中使用apollo配置

a、数据源配置文件database.xml

b、redis配置文件jedis.xml

c、等等,其他需要apollo配置的文件

格式:${键:默认值}   如果阿波罗apollo配置不可用,使用默认值

6、项目启动

 

tomcat中增加启动参数

-Denv=DEV -Dapollo.autoUpdateInjectedSpringProperties=true -Ddev_meta=http://端口号 -Dfile.encoding=UTF-8 

 

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表