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

新建一个SPRINGBOOT项目

配置中心apollo==springboot使用apollo-LMLPHP

<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

配置中心apollo==springboot使用apollo-LMLPHP

配置中心apollo==springboot使用apollo-LMLPHP

03-30 21:44