1
votes

I write Spring Boot application. I use file application.properties to contains configuration of database. But now I want to get properties from application.yml which contains:

rest:
  response: RESPONSE

@RestController
public class MyController {

    @Value("${rest.response}")
    private String restResponse;

    @GetMapping("/foo")
    public ResponseEntity<String> register() {
        return restResponse;
    }
}

Directory resources contains application.properties and application.yml. Why I cannot import properties from .yml?

2
you have both application.properties and application.yml in one directory? - pezetem
yes, I have these files in the same directory - user

2 Answers

0
votes

If you are using 'application.yml' , if the RESPONSE that is read from application.yml contains characters such as + , - etc , put the value inside single inverted commas otherwise it won't be read properly(since it is mapped to a string variable).

0
votes

check that org.yaml:snakeyaml:1.26 is in classpath (or spring-boot-starter is in dependencies)