Reputation: 891
In my Spring-Boot Web Service application, I want to load a property named appName with value defined in application.properties.
@Endpoint
public class RasEndpoint {
private static final String NAMESPACE_URI = "http://www.mycompany.com/schema/ras/ras-request/V1";
@Value("${appName}")
private String appName;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getProductRequest")
@ResponsePayload
public GetProductResponse getProduct(@RequestPayload GetProductRequest request) {
System.out.println("appName: " + appName);
GetProductResponse response = generateStubbedOkResponse();
return response;
}
application.properties has the following entry
appName=ras-otc
I get the application started via the main Application class as shown below
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
However, when I run the app, I get the following error
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'appName' in string value "${appName}"
Do you guys know what I'm doing wrong?
Appreciate any help.
Upvotes: 0
Views: 475
Reputation: 891
As Dave mentioned in the comment above, the properties file was not loaded into the classpath. The properties file was located in /src/main/resources folder, which was added to source, under build path in Eclipse IDE, however had an exclusion rule applied which prevented the properties file from being loaded into the classpath. By removing the exclusion, I was able to load the properties correctly.
Upvotes: 1