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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user