Reputation: 333
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:
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
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:
Upvotes: 0
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:
The list is ordered by precedence (locations higher in the list override lower items).
Upvotes: 1
Reputation: 175
application.properties file should be located in the resource directory.
Upvotes: 3