user5167041 user5167041 - 1 year ago 89
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);

Answer Source

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

String base_url;

Or try a workaround for that:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download