question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
sapessicommented, Dec 22, 2018

Resolving this as a duplicate of #133. Support for both assembly and gradle will go out in version 1.3 shortly

2reactions
mpostupalskicommented, Jun 18, 2018

Ok, I found a workaround. The problem is mainly with application.yml file. With application.properties it works, but you have to provide path to the file with PropertySource annotation as follow:

@SpringBootApplication
@ComponentScan({"foo.bar"})
@PropertySource("classpath:application.properties")
public class Application extends SpringBootServletInitializer {
...
}

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found