refactor: 配置加载顺序单元测试优化
This commit is contained in:
@@ -2,8 +2,9 @@ package com.youlai.system;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* SpringBoot 配置加载顺序单元测试类
|
||||
@@ -11,21 +12,18 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
* @author: haoxr
|
||||
* @date: 2023/02/23
|
||||
*/
|
||||
@SpringBootTest(classes = ConfigLoadOrderTests.class)
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class ConfigLoadOrderTests {
|
||||
|
||||
|
||||
@Value("${config.name}")
|
||||
private String configName;
|
||||
|
||||
/**
|
||||
* 测试配置加载顺序
|
||||
* 测试配置加载顺序
|
||||
*/
|
||||
@Test
|
||||
public void testConfigLoadOrder() {
|
||||
log.info("配置加载顺序 config.name:{}", configName);
|
||||
|
||||
public void testConfigLoadOrder(ApplicationContext context) {
|
||||
Environment environment = context.getEnvironment();
|
||||
String property = environment.getProperty("config.name");
|
||||
log.info(property);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,59 @@
|
||||
config:
|
||||
name: application-dev.yml
|
||||
name: application-dev.yml
|
||||
|
||||
server:
|
||||
port: 8989
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://www.youlai.tech:3306/youlai_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
|
||||
username: youlai
|
||||
password: 123456
|
||||
data:
|
||||
redis:
|
||||
database: 6
|
||||
host: www.youlai.tech
|
||||
port: 6379
|
||||
password: 123456
|
||||
timeout: 10s
|
||||
lettuce:
|
||||
pool:
|
||||
min-idle: 0
|
||||
max-idle: 8
|
||||
max-active: 8
|
||||
max-wait: -1ms
|
||||
|
||||
mybatis-plus:
|
||||
global-config:
|
||||
db-config:
|
||||
# 主键ID类型
|
||||
id-type: none
|
||||
logic-delete-field: deleted
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
configuration:
|
||||
# 驼峰下划线转换
|
||||
map-underscore-to-camel-case: true
|
||||
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
# 认证配置
|
||||
auth:
|
||||
token:
|
||||
secret_key: SecretKey012345678901234567890123456789012345678901234567890123456789
|
||||
# token 有效期(单位:秒)
|
||||
token_validity: 18000
|
||||
|
||||
# MinIO 分布式文件系统
|
||||
minio:
|
||||
endpoint: http://localhost:9000
|
||||
access-key: minioadmin
|
||||
secret-key: minioadmin
|
||||
# 存储桶名称
|
||||
bucket-name: default
|
||||
# 自定义域名(非必须),Nginx配置反向代理转发文件路径
|
||||
custom-domain:
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user