SpringBoot: @Value for Proxy-settings (System.setProperty)
<p>My <code>application.yml</code> configuration looks like this:</p>

<pre><code>proxy:
  host: myProxyDNS
  port: 8080
  trustedStore:
    filename: keystore.jks
    type: JKS
    password: MY_PASSWORD_FOR_THE_KEYSTORE
</code></pre>

<p>The class how manage all the proxy stuff looks like:</p>

<pre><code>@Configuration
public class ProxyConfigurator {

@Value("${proxy.host}")
private String proxyHost;

@Value("${proxy.port}")
private String proxyPort;

@Value("${proxy.trustedStore.filename}")
private String trustedStoreFilename;

@Value("${proxy.trustedStore.type}")
private String trustedStoreType;

@Value("${proxy.trustedStore.password}")
private String trustedStorePassword;

public void setProxy() {
  System.setProperty("https.proxyHost", proxyHost);
  System.setProperty("https.proxyPort", proxyPort);

  System.setProperty("javax.net.ssl.trustStoreType", getPathForFile(trustedStoreFilename));
  // and so on ...
}
</code></pre>

<p>In my "Main" Class which was called by <code>SpringApplication.run()</code> looks like that:</p>

<pre><code>@Autowired
private ProxyConfigurator proxyConfigurator;

@Override
public void run(String... args) throws Exception {
   proxyConfigurator.setProxy();
   // Call another autowired (third-party class) to make an HTTP call
}
</code></pre>

<p>This works fine (all properties are set). BUT in my "main" class i have also some other autowired classes (third-party) which i used to make an HTTP call. The problem is now, that this third-party classes ignore all System properties that are set after their initialization.</p>

<p>I've found some posts on SO where the proxy settings was set by arguments (<code>-D</code>), but i think this not a solution for me. </p>

<p>Sure i can use a second <code>SpringApplication.run</code>: the first one sets the proxy, the second runs my app. But this feels bad.</p>

<p>Have anyone a good suggestion? </p>

<p>Thanks!</p>