0

Ok yall, I've searched high and low. Disclaimer: this is my first Spring project, so I may be just making a mistake.

I am going to deploy an application to the heroku platform. I can push to github main branch, and it will auto deploy to heroku. Long story short: I'm trying to set up my local environment to run it's own database, and the production environment will run its own database (for obvious reasons).

I am using the application.properties, along with the application-{profile}.properties naming convention with these two files: application-local.properties, and application-prod.properties. You can view references to this Stack overflow answer for why, as well as this reference in the spring docs.

I have set my environent variables in my local System, and can access it in cmd, by running echo %WHATEVER_ENV% Issue: this is what my application.properties file looks like : spring.profiles.active=${SPRING_PROFILES_ACTIVE} IF I change this to : spring.profiles.active=local it will read from local, which is hard-coded values. BUT if i change it to prod, it DOES read the correct file, but I get errors (I have set all of these value in my sytem, by the way); My application-prod.properties file reads like this

spring.datasource.url= ${SPRING_DATASOURCE_URL}
spring.datasource.username= ${SPRING_DATASOURCE_USERNAME}
spring.datasource.password= ${SPRING_DATASOURCE_PASSWORD}
spring.jpa.database-platform= ${SPRING_JPA_DATABASE-PLATFORM}
spring.datasource.driver-class-name=org.postgresql.Driver

My "run" log shows this

Factory method 'entityManagerFactory' threw exception; 
nested exception is java.lang.RuntimeException: Driver 
org.postgresql.Driver claims to not accept jdbcUrl, 
${SPRING_DATASOURCE_URL}

^^^This is my issue. It is like spring is just NOT pulling in the env variables. What am I doing wrong?

2 Answers2

0

I apparently needed to set the environmental variables within my IDE. However, I still wonder why the environmental variables did not pull in from my system.

EDIT: the above worked, but also thanks to @Kushal, as his solution was the real solution. I needed to restart my IDE

-1

You would require to restart IDE in order to fetch latest values from environment variables of your system, IDE stores the variable in cache which needs restart in order to refresh