Skip to content
Advertisement

Spring Boot not recognizing application.properties file

I’m trying to configure a DynamoDb client with Spring Boot, and placed my endpoints and configuration information in my resources/application.properties file. However, Spring Boot does not seem to pick up these properties. It does pick up the “server.default” key that I have stored in the same file, so it is definitely recognizing the the file itself.

Here is my application.properties file and the class I’m trying to load properties into (DynamoDBClientMapper):

JavaScript

Here is my project structure: enter image description here

Here is the relevant class I’m trying to load properties into. I tried the @PropertySource annotation with a new properties file, as well as EnableAutoConfiguration, but neither are registering the properties file(s).

JavaScript

Here is my App.java:

JavaScript

Here is the stack trace:

JavaScript

I’ve tried making another separate database.properties file , but Spring Boot isn’t recognizing that either. What am I doing wrong?

Advertisement

Answer

You can make a try to define resources tag in the build section in your pom.xml file. Set path for resource directory where is application.properties

JavaScript

Resource Link: https://stackoverflow.com/a/30595114/2293534

Another approach:

If you use spring 3.X version, You can add @PropertySource("application.properties")

JavaScript

If you use spring 4 version, you add 2 properties file using new annotation called @PropertySources that allows you to declare repeated @PropertySource annotations:

JavaScript

Details is given here in my another answer: https://stackoverflow.com/a/43659158/2293534

UPDATE #1:

Replace your App.java class with following class

JavaScript

For java.io.FileNotFoundException:

Use the following

JavaScript

UPDATE #2:

I have followed the following steps to run your application. It runs successfully.

  1. Go to your project folder where pom.xml is exists.

  2. You have some errors and warning on pom.xml. I have clarified all.

  3. Open command prompt and Run mvn clean

  4. Run mvn clean install

  5. At last mvn spring-boot:run

Then in browser, I run http://localhost:8080/

It opens the project successfully. I have also searched other pages also opened successfully.

First page looks like below http://localhost:8080/

enter image description here

All Review pages look like below: http://localhost:8080/api/reviews

JavaScript

So Replace your pom.xml

JavaScript

Errors and solutions:

Issue #1:

JavaScript

Solution #1:

JavaScript

Issue #2:

JavaScript

Solution #2:

JavaScript

Issue #3:

JavaScript

Solution #3:

JavaScript

Issue #4:

JavaScript

Solution #4:

JavaScript

Issue #5:

JavaScript

Solution #5:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement