0

Is there any way to set the network proxy and credentials in spring boot configuration?

Please help me out.

I'm using RestTemplate to call the rest api.

reto
  • 9,995
  • 5
  • 53
  • 52
chow21
  • 3
  • 1
  • 3
  • 1
    Did you read http://stackoverflow.com/questions/3687670/using-resttemplate-how-to-send-the-request-to-a-proxy-first-so-i-can-use-my-jun ? – reto Jan 20 '16 at 07:36

1 Answers1

2

You should enable proxy using below code snippets

 SimpleClientHttpRequestFactory factory = new   SimpleClientHttpRequestFactory();
    InetSocketAddress address = new InetSocketAddress(host,portNr);
    Proxy proxy = new Proxy(Proxy.Type.HTTP,address);
    factory.setProxy(proxy);

    restTemplate.setRequestFactory(factory);
Pankaj Pandey
  • 1,015
  • 6
  • 10
  • Is there any possibly to configure in application.properties files. – chow21 Jan 21 '16 at 14:15
  • @Goutham Yes possible using PropertySource annotaion and Value annotation. See examplehttp://www.mkyong.com/spring/spring-propertysources-example/ – Pankaj Pandey Jan 21 '16 at 14:48