[英]spring-boot application.properties question -bug
there are three files in application demo ,but the result is wrong return , name is correct ,but the pwd return my project directory why ? 应用程序演示中有三个文件,但是返回错误结果,名称正确,但是pwd返回我的项目目录为什么? a bug ? 一个错误? or pwd is keyword ? 还是pwd是关键字? enter image description here 在此处输入图片说明
1.application.properties: 1.application.properties:
name="Spring Boot"
pwd="love Spring boot"
2.SpringController : 2,SpringController:
@RestController
public class SpringController {
@Value("${name}")
private String name;
@Value("${pwd}")
private String pwd;
@RequestMapping("/")
public String see(){
return name+","+pwd;
}
}
3.DemoApplication 3.DemoApplication
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Spring-boot resolves properties from a variety of sources , each source has a different priority. Spring-boot从各种来源解析属性,每个来源都有不同的优先级。
One of the sources is environment variables, they have a higher priority than application.properties
files. 来源之一是环境变量,它们的优先级高于application.properties
文件。
Most UNIX shells set the environment variable pwd
to be the current working directory, this is why it is replacing your configured value. 大多数UNIX shell将环境变量pwd
设置为当前工作目录,这就是为什么它替换了您配置的值。
Simplest solution is to use a better more specific name for your property. 最简单的解决方案是为您的媒体资源使用更好的特定名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.