How do I add environment variables in IntelliJ Spring Boot project
Asked Answered
I

4

10

I Am trying to add an environmental variable inside my spring-boot application.properties file. I know how to add it normally on a non spring-boot project, but I cannot find the field for adding environment variables, this is all I see:

this is all I see

This is my application.properties file, this may help.

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/FTHLDB
spring.datasource.username=root
spring.datasource.password=${MYSQL_PASS}
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.format_sql=true
Ida answered 12/3, 2022 at 13:39 Comment(1)
what do you mean by "environmental variable" ?Mountfort
O
34

The UI of Run/Debug Configurations has changed. Under 'Modify Options' select 'Environment Variables' under 'Operating System'.

Screenshot of explanation

Outmarch answered 28/4, 2022 at 14:19 Comment(0)
T
1

run -> Edit Configurations -> edit environment variables. enter image description here

Taraxacum answered 12/3, 2022 at 14:4 Comment(1)
..and separate the variables using ;Adulthood
J
0

you can write the environment variable name directly with it's value like this myvariable = its value inside the application.properties file and to use it just inject it inside your method or globally inside your class like this public class MyClass{ @Value("${myvariable}"} String myvariable; }

Jeffersonjeffery answered 12/3, 2022 at 14:0 Comment(0)
M
0
  • Edit Configuration -> Environment Variables -> Add your .env variables here..

Like:

  • My .env file enter image description here

  • Edit Configuration -> Environment Variables enter image description here

Marcela answered 6/2, 2024 at 14:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.