Can't read values from property file
See original GitHub issue- Framework version: 1.1
- Implementations: Spring Boot
Scenario
Once app is starting I want to have possibility to read values from properties file ie. application.yml. I have defined app as below:
@SpringBootApplication
@ComponentScan({"foo.bar"})
public class Application extends SpringBootServletInitializer {
@Value("${foo.clientId}")
private String clientId;
}
Once app is up and running clientId
should be populated with values provided in the file.
I have configured handler as provided in Readme file:
public class StreamLambdaHandler implements RequestStreamHandler {
private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
try {
handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);
} catch (ContainerInitializationException e) {
// if we fail here. We re-throw the exception to force another cold start
e.printStackTrace();
throw new RuntimeException("Could not initialize Spring Boot application", e);
}
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);
// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Expected behavior
Filed clientId
populated with value from properties file
Actual behavior
Exception during lambda start process:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'application': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'foo.clientId' in value "${foo.clientId}"
Steps to reproduce
Create app as above, create properties file, put placeholders, deploy on AWS and run.
Full log output
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Top Results From Across the Web
Springboot can't read values from properties file - Stack Overflow
properties file. However I'm trying, It's always getting 0.00 as a value. You may need either to add @Configuration annotation to ...
Read more >Spring Boot Read Values from Application Properties File
And in this article, I'd love to share with you how to read or bind values of properties in Spring application configuration file...
Read more >How to Read config.properties Values in Java? - Crunchify
Step-1: Create config.properties file. Create Folder “ resources ” under Java Resources folder if your project doesn't have it.
Read more >Read From Application.properties file in SpringBoot - YouTube
Your browser can't play this video. ... Read From Application. properties file in SpringBoot |@ Value disallowed for this location springboot.
Read more >Using Properties for Configuration Data - Java and OOP
These are all things that may change and we don't want to “hard code” the values ... Java has support for reading and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Resolving this as a duplicate of #133. Support for both assembly and gradle will go out in version 1.3 shortly
Ok, I found a workaround. The problem is mainly with
application.yml
file. Withapplication.properties
it works, but you have to provide path to the file withPropertySource
annotation as follow:However it doesn’t work perfectly as I tried turn off a banner (
spring.main.banner-mode=off
) but it still appears in the CloudWatch logs.