You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

27 lines
950 B

package cc.bnblogs.annotations;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
/**
* 测试类读取配置文件信息
* 临时修改配置文件中的值
* 临时属性优先级大于配置文件属性
*/
// 方法1:在@SpringBootTest注解上添加properties属性,设置和配置文件一样的属性,并设置值(优先级比@Value高)
// 方法2:在@SpringBootTest注解上添加args的参数,并设置值--bnblogs.author=admin
// 如果同时设置了两种参数,将使用properties设置的值
//@SpringBootTest(properties = "bnblogs.author=tom")
@SpringBootTest(args = "--bnblogs.author=admin",properties = "bnblogs.author=tom")
class AnnotationsApplicationTests {
@Value("${bnblogs.author}")
private String blogAuthor;
@Test
void contextLoads() {
System.out.println(blogAuthor);
}
}