user5167041 user5167041 - 2 months ago 15
Java Question

Spring Boot- Fail to retrieve application.yml variable value using @Value

I am trying to retrieve my base_url that is stored in the application.yml from my @RestController. However, when I use the code printed below, it always return null. Can someone please let me know why @Value("${base_url}") always return null? Thanks in advance.

Rest Controller:

public class AccountController {

static String base_url;

@RequestMapping(method = RequestMethod.GET, value = "/getAccount")
public ResponseEntity<Object> getAccount() {



public class TestApplication {

public static void main(String[] args) {, args);


You can't use static field, then you should do this:

String base_url;

Or try a workaround for that: