spring boot .env variables in application.properties
This won't happen automatically. You can make it work by adding this to your application-dev.properties
:
spring.config.import=optional:file:.env[.properties]
Another option is to use an additional library that adds support for this, such as https://github.com/paulschwarz/spring-dotenv.
There is some discussion about adding support for this in Spring Boot, but it is not a high priority.
environment variables in Spring-Boot in email data in application.properties
It should work, but you doesn't specify what is not working. To make these properties useful you have to wire the right Spring Boot plugin and obviously use it in your code:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.7.0</version>
</dependency>
// wire it in your bean
@Autowired
private JavaMailSender emailSender;
// reference the emailSender and send emails ...
Using system variable in Spring Boot's application.properties
Of course you can read environment variables from properties file. Provided username is configured as environment variable in the system you want to execute the code on.
simply replace,
this: logfile.dir=/Users/Nunito/logs/icrypts/
with: logfile.dir=/Users/${userName}/logs/icrypts/
You can also read properties file using any of below ways.
@Value("${username}")
private String username;
You can also use, SPRING_APPLICATION_JSON
At application startup, Spring Boot will look for an environment variable called SPRING_APPLICATION_JSON. It can be used to provide a set of application properties using inline JSON. For example, you can set ec2.public.url property as follows.
You can refer samples from here,
https://github.com/indrekots/spring-boot-envvariables
Related Topics
How to Directly Initialize a Hashmap (In a Literal Way)
How to Map a Composite Key with JPA and Hibernate
Java, Classpath, Classloading => Multiple Versions of the Same Jar/Project
Connecting to Remote Url Which Requires Authentication Using Java
What Is the "Execute Around" Idiom
How to Get Current Moment in Iso 8601 Format with Date, Hour, and Minute
What Is the Exact Meaning of Static Fields in Java
How to Execute Cmd Commands via Java
Slf4J: Failed to Load Class "Org.Slf4J.Impl.Staticloggerbinder"
Can Enums Be Subclassed to Add New Elements
Returning from a Finally Block in Java
Why Can't Overriding Methods Throw Exceptions Broader Than the Overridden Method
How to Get a List of Dates Between Two Dates in Java
How to Load a Jar File at Runtime