Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to fetch property

I have defined few properties in my application.properties:

path.tools=/app/tools

In code I try to fetch it as:

System.getenv("path.tools");

But it returns null.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I also tried:

System.getProperty("path.tools");

App is running in docker.

What am I missing in my setup?

>Solution :

For you to be able to get it with System.getenv you would have needed to define it as an environment variable first.

For you to be able to read it from System.getProperty you would have needed to have set that system property first with System.setProperties OR to have tried reading one of predefined System properties

To read properties that are read by Spring either:

1. Autowire the property with @Value

@Value("${path.tools}")
String pathTools;

2. Read them from Environment class (that you can autowire)

@Autowired
Environment environment;

public void foo() {
    environment.getProperty("path.tools");
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading