Listing system / spring environment properties

Ladies & Gents, I prototyped just a small app that could help you print out some basic environment related information by exposing a few Rest controller endpoints.

Running the app

The easiest way is to run the app using Spring boot maven plugin

$ mvn spring-boot:run \
    -Dfoo=foo \
    -Dbar=bar \
    -Dbaz=baz \
    -Dserver.port=8080 \

Here, we specify some Java properties that will be used by the application:

  • foo, bar, baz custom properties
  • server.port – which is the way to instruct Spring Boot which port to use
  • we also specify to start with remote debug capabilities (if we’d like to do some remote debugging with our IDE)

Rest controller exposing various system / spring properties

package rs.dodalovic.envprops;

import lombok.AllArgsConstructor;
import lombok.val;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

public class EnvPropertiesController {
    private final Environment environment;

    public Map<String, Object> getSysProperties() {
        val builder = ImmutableMap.builder();
        System.getProperties().stringPropertyNames().forEach(name -> {
            builder.put(name, environment.getProperty(name));
        val systemProperties =;
        return ImmutableMap.of(
                "size", systemProperties.size(),
                "values", systemProperties

    public Map<String, Object> getCustomEnvProperties() {
        val builder = ImmutableMap.builder();
        builder.put("properties.key1", environment.getProperty("properties.key1"));
        builder.put("properties.key2", environment.getProperty("properties.key2"));

        builder.put("foo", environment.getProperty("foo"));
        builder.put("bar", environment.getProperty("bar"));
        builder.put("baz", environment.getProperty("baz"));

        val customProperties =;

        return ImmutableMap.of(
                "size", customProperties.size(),
                "values", customProperties

    public Map<String, Object> get() {
        val env = System.getenv();
        return ImmutableMap.of(
                "size", env.size(),
                "values", env

Highlighted are lines used to get insights from running application environment. We are injecting Environment implementation which gives us access to environment properties, and application profiles.


In the (main Spring Boot configuration file) we define two custom Spring environment properties: properties.key1 and properties.key2.

Listing system properties

$ curl -s 'http://localhost:8080/sys/props' | jq .


   "size": 63,
   "values": {
     "": "Java(TM) SE Runtime Environment",
     "sun.boot.library.path": "/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib",
     "java.vm.version": "25.121-b13"
     // ...

Listing system environment

$ curl -s 'http://localhost:8080/sys/env' | jq .


  "size": 46,
  "values": {
    "M2": "/usr/local/Cellar/maven/3.5.0/libexec/bin",
    "GREP_COLOR": "1;33",
    // ...

 Listing custom spring properties

$ curl -s 'http://localhost:8080/sys/props/custom' | jq .


  "size": 5,
  "values": {
    "properties.key1": "properties.val1",
    "properties.key2": "properties.val2",
    "foo": "foo",
    "bar": "bar",
    "baz": "baz"

Here we see merged collection of environment properties we either passed via command line or defined in

You can checkout source code from GitHub

Hope you’ll find this useful. If so – don’t forget to subscribe to get notified of upcoming posts.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s