简体   繁体   English

春季启动application.properties问题-bug

[英]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.

相关问题 spring-boot application.properties中的环境变量错误 - Environment Variables in spring-boot application.properties error Spring-Boot>使用JNDI设置application.properties - Spring-Boot > Setting application.properties using JNDI application.properties 中电子邮件数据中 Spring-Boot 中的环境变量 - environment variables in Spring-Boot in email data in application.properties 覆盖application.properties以在Spring-boot应用程序中进行集成测试 - Override application.properties for integration tests in spring-boot app 如何在 Spring-Boot 的生产过程中覆盖 application.properties? - How to override application.properties during production in Spring-Boot? spring-boot如何添加多个application.properties文件? - How to add multiple application.properties files in spring-boot? Spring-Boot中的application.properties属性的UTF-8编码 - UTF-8 encoding of application.properties attributes in Spring-Boot Spring-boot - 参数化测试 - 访问MethodSource中的Application.properties - Spring-boot - Parameterized Test - Access Application.properties in MethodSource 用application.properties覆盖默认的Spring-Boot application.properties - Override default Spring-Boot application.properties with application.properties Application.properties spring-boot 在 pom.xml 中产生错误。 application.properties 中的 mysql 连接存在问题 - Application.properties spring-boot produce an error in pom.xml. Problem with mysql connection in application.properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM