"java.net.UnknownHostException" Displayed When Compiling Spring Boot
Symptom
The message "java.net.UnknownHostException" is displayed when "self-signed.badssl.com" is accessed during the Spring Boot compilation.

Key Process and Cause Analysis
The host is not mapped. Add proxy configurations to solve the problem.
Conclusion and Solution
- Open the ReactiveCloudFoundrySecurityService.java file.
vim ./spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java
- Press i to enter the insert mode and modify the file.
- Add the following content below line 27:
import reactor.netty.tcp.ProxyProvider;

- Insert the following code in line 64:
else { HttpClient client = HttpClient.create().tcpConfiguration(tcpClient -> { tcpClient = tcpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP).host("127.0.0.1") .port(3128).nonProxyHosts("localhost|my*.com").build()); return tcpClient; }); webClientBuilder.clientConnector(new ReactorClientHttpConnector(client)); }In the preceding example, 127.0.0.1 and 3128 indicate the IP address and port number of the proxy host. Replace them with the actual ones.

- Modify the content in line 77 as follows:
HttpClient client = HttpClient.create().tcpConfiguration(tcpClient -> { tcpClient = tcpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP).host("127.0.0.1").port(3128) .nonProxyHosts("localhost|my*.com").build()); return tcpClient; }).secure((sslContextSpec) -> sslContextSpec.sslContext(createSslContext())); return new ReactorClientHttpConnector(client);In the preceding example, 127.0.0.1 and 3128 indicate the IP address and port number of the proxy host. Replace them with the actual ones.

Run the :set list command to check the format. Spaces are not allowed. Use Tab to indent the code.
- Add the following content below line 27:
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Recompile Spring Boot.
Parent topic: Troubleshooting