1

Did there have any way to set or put some values into org.springframework.core.env.Environment?

We are using Spring-boot as below version.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.1.RELEASE</version>
</parent>

Spring will load application.properties into org.springframework.core.env.Environment by default. We can @Autowired Environment and getString("key") to get the value.

Say we have a license file and will decoding it to load the licensing period to validate if this system is still valid or not, at the initialize() of ApplicationContextInitializer.

We would like to save this licensing period into Environment for using later. For example, We will validate the licensing period again when user has sending some specified requests each time. So that, we don't have to load the license file in and decode it each time.

Or can we achieve this purpose in any others way which is more appropriately?

Any help is appreciated.

Bruce
  • 647
  • 2
  • 12
  • 30

1 Answers1

0

You can refer to this to read from properties file.

If you want to make it env specific. Then make your properties file as

license-{env}.properties. In this way it will load the properties file for the current Env.

Ekansh Rastogi
  • 2,418
  • 2
  • 14
  • 23
  • Hi Ekansh, thanks for the reply. But, our license file is encrypted, so I am afraid that we couldn't let it to be loaded as a properties file. We are looking for some ways to store/set/put value into environment as a global variable. – Bruce Apr 03 '16 at 12:47