Skip to content

Instantly share code, notes, and snippets.

@unamanic
Created November 11, 2016 17:43
Show Gist options
  • Save unamanic/a7eb0c17b78fb03617cc955b06285b1d to your computer and use it in GitHub Desktop.
Save unamanic/a7eb0c17b78fb03617cc955b06285b1d to your computer and use it in GitHub Desktop.
Setting system properties from config server (or application.properties)
package com.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
@SpringBootApplication
public class SystemPropertiesApplication implements CommandLineRunner{
public static void main(String[] args) {
SpringApplication.run(SystemPropertiesApplication.class, args);
}
private final Environment env;
@Autowired
public SystemPropertiesApplication(Environment env) {
this.env = env;
}
@Override
public void run(String... strings) throws Exception {
if(env.containsProperty("system.javax.net.ssl.keyStore")) {
String keystore = env.getProperty("system.javax.net.ssl.keyStore");
System.out.println(keystore);
System.getProperties().setProperty("javax.net.ssl.keyStore", keystore);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment