SpringBoot is not picking Application.properties from src/main/resources

48 Views Asked by At

I'm using SpringBoot 3.x and myBatis. When I start my application, tomcat is not picking my application properties instead it is taking the default testDB url and gives me the error as mentioned in the screenshot belowError message

My application properties is under src/main/resources and after maven build is successful it is present under target/classes. I have set the spring.profile.active=local in the application properties.

In the Run Configuration, I tired two methods to tell springboot to load my application properties

  1. Tried adding the VM options as -Dspring.config.location=application.properties and set the active to "local" but didnt work and gives out the same error as shown in the screenshot

  2. I tried adding program arguments as --spring-config-location=application.properties and set the active to "local", this didnt work too and gives out the same error as shown in the screenshot

1

There are 1 best solutions below

3
JUDE On

what IDE are you using ?

You might need to mark the resourse folder as your Resource root

Check for other configurations: Make sure there are no conflicting configurations in your application, such as other property sources that might be overriding the values specified in application.properties.

VM Options or Program Arguments: The correct option to specify the location of the application properties file is -Dspring.config.location=classpath:application.properties for VM options and --spring.config.location=classpath:application.properties for program arguments. Make sure you are using the correct syntax and that the path to the properties file is correct.