配置中心apollo==springboot使用apollo

多环境的APOLLO之前已经搭建好了。

新建一个SPRINGBOOT项目

<dependency>
  <groupId>com.ctrip.framework.apollo</groupId>
  <artifactId>apollo-client</artifactId>
  <version>2.2.0</version>
</dependency>

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.5.5</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo-apollo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo-apollo</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>8</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.ctrip.framework.apollo</groupId>
			<artifactId>apollo-client</artifactId>
			<version>2.1.0</version>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<excludes>
						<exclude>
							<groupId>org.projectlombok</groupId>
							<artifactId>lombok</artifactId>
						</exclude>
					</excludes>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>

package com.example.demoapollo;

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.List;

@EnableApolloConfig
@SpringBootApplication
public class DemoApolloApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext con = SpringApplication.run(DemoApolloApplication.class, args);

    }

}


app:
  # ??ID
  id: appid03301
apollo:
  # ????????????????Apollo ?????????????
  cache-dir: C:\opt\data
  # Spring??????? Placeholder ???????${someKey:someDefaultValue}??????? key???????????????? placeholder ???????????????? false
  autoUpdateInjectedSpringProperties: true
  bootstrap:
    # ???? Apollo ???
    enabled: true
    eagerLoad:
      # ? Apollo ??????????????????? false??????? Apollo ???????????? Apollo ????????????????????????????? Apollo ????????????????? true??? Apollo ????????????????? Apollo ??????
      enabled: true
    # ???????? properties??????yml????????.yml
#    namespaces: meta.yml,data_product.common.yml,data_product.redis.yml,data_product.mq.yml,data_product.hbase.yml
    namespaces: meta.yml
  # Apollo ??????ConfigServiceLocator
  config-service: http://localhost:8080
server:
  port: 9999
logging:
  level:
    com.ctrip: debug
key1: test11111

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值