I am trying to access a custom property from application.properties (present in src/main/resources) of my Spring Boot rest application and trying to access that value from my controller
Spring boot application class location "src/main/java/com/myapp/FileReaderApp.java"
package com.myapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FileReaderApp {
public static void main(String[] args) {
SpringApplication.run(FileReaderApp.class, args);
}
}
Controller class location : "src/main/java/com/myapp/controller/FileReaderController.java"
@RestController
@RequestMapping("/counter-api")
public class FileReadController {
@Value("${fileLocation}")
static private String fileLocation;
//do other actions
}
I found out i couldnt do it at all and everytime fileLocation is coming as null.
My application.properties file has only one property, fileLocation.
Could anyone please advise where I am going wrong in this case and what is the best way to access an application property value in REST Controller class?