I have a simple Springboot app that can be ran with the command: ./mvnw spring-boot:run. This works fine if I put the URI to my database inside of the application.properties file but the problem is that this file is used by Heroku, and is not meant for my local use.
So I came across a Stackoverflow answer that said I could simply make another .properties file but name it application-dev.properties and then when I run my app, the correct .properties file will automatically be chosen when I set the active profile to dev.
So I tried this by doing the following:
- Make the
application.propertiesfile use the environment variable from Heroku since this is the.propertiesfile I do NOT want to use locally. - I created a
.propertiesfile calledapplication-dev.propertiesthat has this line in it:
spring.data.mongodb.uri=mongodb+srv://MY_NAME:[email protected]/Employees?retryWrites=true&w=majority
- I run the app like this:
./mvnw spring-boot:run -Dspring.profiles.active=dev - The app fails with a ton of different errors because it is trying to use the
application.propertiesfile and not theapplication-dev.propertiesfile
Part of the error message:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeController': Unsatisfied dependency expressed through field 'employeeRepo';