haigang deng
haigang deng

Reputation: 1

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 ? a bug ? or pwd is keyword ? enter image description here

1.application.properties:

name="Spring Boot"
pwd="love Spring boot"

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

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {

        SpringApplication.run(DemoApplication.class, args);
    }
}

Upvotes: 0

Views: 316

Answers (1)

Magnus
Magnus

Reputation: 8300

Spring-boot resolves properties from a variety of sources, each source has a different priority.

One of the sources is environment variables, they have a higher priority than application.properties files.

Most UNIX shells set the environment variable pwd to be the current working directory, this is why it is replacing your configured value.

Simplest solution is to use a better more specific name for your property.

Upvotes: 1

Related Questions