Commit b8015e87b386ffd42fcb92cdcd6fe726b83281a2

Authored by YunaiV
1 parent 612861c9

提供一个 Spring Boot 读取多配置文件的示例

src/main/java/cn/iocoder/dashboard/DashboardApplication.java
... ... @@ -5,10 +5,14 @@ import org.springframework.boot.SpringApplication;
5 5 import org.springframework.boot.autoconfigure.SpringBootApplication;
6 6  
7 7 @SpringBootApplication
8   -@EnableAdminServer
  8 +@EnableAdminServer // TODO 芋艿:需要迁移出去
9 9 public class DashboardApplication {
10 10  
11 11 public static void main(String[] args) {
  12 + // 设置读取的配置文件
  13 + System.setProperty("spring.config.name", "application,db");
  14 +
  15 + // 启动 Spring Boot
12 16 SpringApplication.run(DashboardApplication.class, args);
13 17 }
14 18  
... ...
src/main/resources/application.yaml
... ... @@ -2,13 +2,6 @@ spring:
2 2 application:
3 3 name: dashboard
4 4  
5   - # 数据源配置项 TODO 多数据源;TODO 监控配置
6   - datasource:
7   - url: jdbc:mysql://127.0.1:33061/ruoyi-vue-pro?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
8   - driver-class-name: com.mysql.jdbc.Driver
9   - username: root
10   - password: 123456
11   -
12 5 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
13 6 redis:
14 7 host: 127.0.0.1 # 地址
... ...
src/main/resources/db.yaml 0 → 100644
  1 +spring:
  2 + # 数据源配置项 TODO 多数据源;TODO 监控配置
  3 + datasource:
  4 + url: jdbc:mysql://127.0.1:33061/ruoyi-vue-pro?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
  5 + driver-class-name: com.mysql.jdbc.Driver
  6 + username: root
  7 + password: 123456
... ...