-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
290 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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> | ||
<artifactId>spring-boot</artifactId> | ||
<groupId>com.git.hui.boot</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>001-properties-env-mvn</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<!-- 开发 --> | ||
<profile> | ||
<id>dev</id> | ||
<properties> | ||
<env>dev</env> | ||
</properties> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
</profile> | ||
<!-- 测试 --> | ||
<profile> | ||
<id>test</id> | ||
<properties> | ||
<env>test</env> | ||
</properties> | ||
</profile> | ||
<!-- 预发 --> | ||
<profile> | ||
<id>pre</id> | ||
<properties> | ||
<env>pre</env> | ||
</properties> | ||
</profile> | ||
<!-- 生产 --> | ||
<profile> | ||
<id>prod</id> | ||
<properties> | ||
<env>prod</env> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
</resource> | ||
<resource> | ||
<directory>src/main/resources-env/${env}</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## 001-properites-env-mvn | ||
|
||
### 项目说明 | ||
|
||
基于mvn的多环境配置选择,主要适用于每个环境下,都有很多配置文件的场景; | ||
|
||
此时通过指定maven中profile,激活对应的环境,然后在打包的时候可以将路径下的配置文件都打在一起 | ||
|
||
```bash | ||
# mvn 指定环境打包操作 | ||
mvn clean package -DskipTest=ture -P prod | ||
``` | ||
|
||
### 博文说明 | ||
|
||
本项目对应的博文内容为 | ||
|
44 changes: 44 additions & 0 deletions
44
spring-boot/001-properties-env-mvn/src/main/java/com/git/hui/boot/env/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.git.hui.boot.env; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author yihui | ||
* @date 2022/4/20 | ||
*/ | ||
@Controller | ||
@EnableConfigurationProperties({DalConfig.class}) | ||
@SpringBootApplication | ||
public class Application { | ||
private DalConfig dalConfig; | ||
|
||
public Application(DalConfig dalConfig, Environment environment) { | ||
this.dalConfig = dalConfig; | ||
System.out.println(dalConfig); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication application = new SpringApplication(Application.class); | ||
application.run(args); | ||
} | ||
|
||
|
||
@GetMapping(path = {"", "/", "/index"}) | ||
public ModelAndView index() { | ||
Map<String, Object> data = new HashMap<>(2); | ||
data.put("info", dalConfig); | ||
data.put("now", LocalDateTime.now().toString()); | ||
return new ModelAndView("index", data); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
spring-boot/001-properties-env-mvn/src/main/java/com/git/hui/boot/env/DalConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.git.hui.boot.env; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* @author yihui | ||
* @date 2022/4/20 | ||
*/ | ||
@Data | ||
@ConfigurationProperties(prefix = "spring.datasource") | ||
public class DalConfig { | ||
private String url; | ||
|
||
private String username; | ||
|
||
private String password; | ||
} |
5 changes: 5 additions & 0 deletions
5
spring-boot/001-properties-env-mvn/src/main/resources-env/dev/application-dal.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://127.0.0.1:3306/story?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai | ||
username: root | ||
password: |
5 changes: 5 additions & 0 deletions
5
spring-boot/001-properties-env-mvn/src/main/resources-env/pre/application-dal.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://pre.hhui.top/story?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai | ||
username: pre_root | ||
password: |
5 changes: 5 additions & 0 deletions
5
spring-boot/001-properties-env-mvn/src/main/resources-env/prod/application-dal.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://prod.hhui.top/story?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai | ||
username: prod_root | ||
password: |
5 changes: 5 additions & 0 deletions
5
spring-boot/001-properties-env-mvn/src/main/resources-env/test/application-dal.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://test.hhui.top/story?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai | ||
username: test_root | ||
password: |
19 changes: 19 additions & 0 deletions
19
spring-boot/001-properties-env-mvn/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
spring: | ||
profiles: | ||
active: dal,web | ||
thymeleaf: | ||
mode: HTML | ||
encoding: UTF-8 | ||
servlet: | ||
content-type: text/html | ||
cache: false | ||
|
||
server: | ||
port: 8080 | ||
tomcat: | ||
accesslog: | ||
enabled: true | ||
directory: /logs/boot | ||
file-date-format: .yyyyMMdd | ||
pattern: '%h %l %u %t "%r" %s %b %Dms "%{Referer}i" "%{User-Agent}i" "%{X-Request-ID}i" "%{X-Forwarded-For}i"' | ||
# basedir: /logs |
16 changes: 16 additions & 0 deletions
16
spring-boot/001-properties-env-mvn/src/main/resources/static/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.title { | ||
color: #c00; | ||
font-weight: normal; | ||
font-size: 2em; | ||
} | ||
|
||
.content { | ||
color: darkblue; | ||
font-size: 1.2em; | ||
} | ||
|
||
.sign { | ||
color: lightgray; | ||
font-size: 0.8em; | ||
font-style: italic; | ||
} |
22 changes: 22 additions & 0 deletions
22
spring-boot/001-properties-env-mvn/src/main/resources/templates/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="description" content="SpringBoot thymeleaf"/> | ||
<meta name="author" content="YiHui"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<title>YiHui's SpringBoot Demo</title> | ||
</head> | ||
<body> | ||
|
||
<div> | ||
<div class="title">hello world!</div> | ||
<br/> | ||
<div class="content" th:text="'配置信息:' + ${info}">默认的内容</div> | ||
<br/> | ||
<div class="sign" th:text="'当前时间' + ${now}">默认的签名</div> | ||
<br/> | ||
</div> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
spring-boot/001-properties-env-mvn/target/classes/application-dal.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://prod.hhui.top/story?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai | ||
username: prod_root | ||
password: |
19 changes: 19 additions & 0 deletions
19
spring-boot/001-properties-env-mvn/target/classes/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
spring: | ||
profiles: | ||
active: dal,web | ||
thymeleaf: | ||
mode: HTML | ||
encoding: UTF-8 | ||
servlet: | ||
content-type: text/html | ||
cache: false | ||
|
||
server: | ||
port: 8080 | ||
tomcat: | ||
accesslog: | ||
enabled: true | ||
directory: /logs/boot | ||
file-date-format: .yyyyMMdd | ||
pattern: '%h %l %u %t "%r" %s %b %Dms "%{Referer}i" "%{User-Agent}i" "%{X-Request-ID}i" "%{X-Forwarded-For}i"' | ||
# basedir: /logs |
Binary file added
BIN
+2.13 KB
spring-boot/001-properties-env-mvn/target/classes/com/git/hui/boot/env/Application.class
Binary file not shown.
Binary file added
BIN
+2.4 KB
spring-boot/001-properties-env-mvn/target/classes/com/git/hui/boot/env/DalConfig.class
Binary file not shown.
16 changes: 16 additions & 0 deletions
16
spring-boot/001-properties-env-mvn/target/classes/static/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.title { | ||
color: #c00; | ||
font-weight: normal; | ||
font-size: 2em; | ||
} | ||
|
||
.content { | ||
color: darkblue; | ||
font-size: 1.2em; | ||
} | ||
|
||
.sign { | ||
color: lightgray; | ||
font-size: 0.8em; | ||
font-style: italic; | ||
} |
22 changes: 22 additions & 0 deletions
22
spring-boot/001-properties-env-mvn/target/classes/templates/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="description" content="SpringBoot thymeleaf"/> | ||
<meta name="author" content="YiHui"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<title>YiHui's SpringBoot Demo</title> | ||
</head> | ||
<body> | ||
|
||
<div> | ||
<div class="title">hello world!</div> | ||
<br/> | ||
<div class="content" th:text="'配置信息:' + ${info}">默认的内容</div> | ||
<br/> | ||
<div class="sign" th:text="'当前时间' + ${now}">默认的签名</div> | ||
<br/> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters