Skip to content

Commit 0f79b37

Browse files
committed
Spring Boot 2.4 多环境配置支持的变更
1 parent f66a3f3 commit 0f79b37

File tree

7 files changed

+143
-0
lines changed

7 files changed

+143
-0
lines changed

2.x/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@
5959
- [Spring Boot 2.x基础教程:版本关系](http://blog.didispace.com/spring-cloud-alibaba-version/)
6060
- [Spring Boot 2.x基础教程:快速入门](http://blog.didispace.com/spring-boot-learning-21-1-1/)
6161
- [Spring Boot 2.x基础教程:工程结构推荐](http://blog.didispace.com/spring-boot-learning-21-1-2/)
62+
63+
### 配置文件
64+
6265
- [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/)
66+
- [Spring Boot 2.x基础教程:多环境配置(2.4版本开始的变化)](http://blog.didispace.com/spring-boot-learning-24-1-4/)
6367

6468
### Web开发
6569

2.x/README_zh.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@
5858
- [Spring Boot 2.x基础教程:版本关系](http://blog.didispace.com/spring-cloud-alibaba-version/)
5959
- [Spring Boot 2.x基础教程:快速入门](http://blog.didispace.com/spring-boot-learning-21-1-1/)
6060
- [Spring Boot 2.x基础教程:工程结构推荐](http://blog.didispace.com/spring-boot-learning-21-1-2/)
61+
62+
### 配置文件
63+
6164
- [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/)
65+
- [Spring Boot 2.x基础教程:多环境配置(2.4版本开始的变化)](http://blog.didispace.com/spring-boot-learning-24-1-4/)
6266

6367
### Web开发
6468

2.x/chapter1-2/.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
HELP.md
2+
/target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
.sts4-cache
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
20+
### NetBeans ###
21+
/nbproject/private/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/
26+
/build/
27+
28+
### VS Code ###
29+
.vscode/

2.x/chapter1-2/pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.4.1</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.didispace</groupId>
12+
<artifactId>chapter1-2</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>chapter1-2</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-test</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-maven-plugin</artifactId>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
43+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.didispace.chapter12;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@SpringBootApplication
10+
public class Chapter12Application {
11+
12+
public static void main(String[] args) {
13+
SpringApplication.run(Chapter12Application.class, args);
14+
}
15+
16+
@RestController
17+
static class HelloController {
18+
19+
@Value("${name:}")
20+
private String name;
21+
22+
@RequestMapping("/")
23+
public String index() {
24+
return name;
25+
}
26+
27+
}
28+
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 默认激活dev配置
2+
spring:
3+
profiles:
4+
active: "dev"
5+
6+
---
7+
8+
spring:
9+
config:
10+
activate:
11+
on-profile: "dev"
12+
13+
name: dev.didispace.com
14+
15+
---
16+
17+
spring:
18+
config:
19+
activate:
20+
on-profile: "test"
21+
22+
name: test.didispace.com
23+
24+
---
25+
26+
spring:
27+
config:
28+
activate:
29+
on-profile: "prod"
30+
31+
name: prod.didispace.com

2.x/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<!--快速入门-->
1313
<module>chapter1-1</module>
1414

15+
<!--配置文件-->
16+
<module>chapter1-2</module>
17+
1518
<!--API开发-->
1619
<module>chapter2-1</module> <!-- 构建RESTful API与单元测试 -->
1720
<module>chapter2-2</module> <!-- 使用Swagger2构建强大的API文档 -->

0 commit comments

Comments
 (0)