Alex_X1
Alex_X1

Reputation: 333

Spring not detecting application.properties

Spring is not detecting my application.properties in the config folder. The config file: (Sensitive Information hidden)

server.port = 8090
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:URL}:3306/DB
spring.datasource.username=USER
spring.datasource.password=PW
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
debug=true

Folder structure:

https://i.sstatic.net/62nsY.png

Server.java

@SpringBootApplication
@EnableAutoConfiguration
public class Server {
    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(Server.class);
        application.run();
    }
}

I tried putting the properties in he top and resources folder, nothing seems to work. If I try to load it via VM options it says resource not found. The config folder is marked as resource folder in IntelliJ

Upvotes: 3

Views: 2131

Answers (3)

Alex_X1
Alex_X1

Reputation: 333

The problem has been solved. The home directory for the run configuration needs to be set to the folder containing the resources folder. Which it wasn't before. Folder Structure now:Folder Structure

Upvotes: 0

Sagar Gandhi
Sagar Gandhi

Reputation: 965

Spring has certain order for finding application.properties

Reference : https://docs.spring.io/spring-boot/docs/1.0.1.RELEASE/reference/html/boot-features-external-config.html

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:

  • A /config subdir of the current directory.
  • The current directory
  • A classpath /config package
  • The classpath root

The list is ordered by precedence (locations higher in the list override lower items).

Upvotes: 1

viglu
viglu

Reputation: 175

application.properties file should be located in the resource directory.

Upvotes: 3

Related Questions