mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
Apollo 配置加载顺序示例
This commit is contained in:
@@ -18,16 +18,15 @@ public class JasyptTest {
|
||||
@Test
|
||||
public void encode() {
|
||||
// 第一个加密
|
||||
// String applicationName = "demo-application";
|
||||
// System.out.println(encryptor.encrypt(applicationName));
|
||||
String applicationName = "demo-application";
|
||||
System.out.println(encryptor.encrypt(applicationName));
|
||||
|
||||
// // 第二个加密
|
||||
applicationName = "demo-app";
|
||||
System.out.println(encryptor.encrypt(applicationName));
|
||||
// applicationName = "demo-app";
|
||||
// System.out.println(encryptor.encrypt(applicationName));
|
||||
}
|
||||
|
||||
@Value("${spring.application.name}")
|
||||
// @NacosValue("${spring.application.name}")
|
||||
private String applicationName;
|
||||
|
||||
@Test
|
||||
|
||||
30
lab-45/lab-45-apollo-demo-multi/pom.xml
Normal file
30
lab-45/lab-45-apollo-demo-multi/pom.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-45-apollo-demo-multi</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 实现对 SpringMVC 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Apollo 客户端,内置对 Apollo 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>com.ctrip.framework.apollo</groupId>
|
||||
<artifactId>apollo-client</artifactId>
|
||||
<version>1.5.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.iocoder.springboot.lab45.apollodemo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 启动 Spring Boot 应用
|
||||
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
|
||||
|
||||
// 查看 Environment
|
||||
Environment environment = context.getEnvironment();
|
||||
System.out.println(environment);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.springboot.lab45.apollodemo.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/demo")
|
||||
public class DemoController {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@GetMapping("/test")
|
||||
public void test() {
|
||||
System.out.println(environment);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
server:
|
||||
port: 7070 # 避免和本地的 Apollo Portal 端口冲突
|
||||
|
||||
app:
|
||||
id: demo-application-multi # 使用的 Apollo 的项目(应用)编号
|
||||
apollo:
|
||||
meta: http://127.0.0.1:8080 # Apollo Meta Server 地址
|
||||
bootstrap:
|
||||
enabled: true # 是否开启 Apollo 配置预加载功能。默认为 false。
|
||||
eagerLoad:
|
||||
enable: true # 是否开启 Apollo 支持日志级别的加载时机。默认为 false。
|
||||
namespaces: application, db # 使用的 Apollo 的命名空间,默认为 application。
|
||||
@@ -16,6 +16,7 @@
|
||||
<module>lab-45-apollo-demo-profiles</module>
|
||||
<module>lab-45-apollo-demo-auto-refresh</module>
|
||||
<module>lab-45-apollo-demo-jasypt</module>
|
||||
<module>lab-45-apollo-demo-multi</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user