编译Spring Boot时SampleOAuth2ClientApplicationTests.java文件问题的解决方法
问题现象描述
编译Spring Boot过程中需要访问“api.login.yahoo.com”,提示“UnKnownHostException: api.login.yahoo.com”。
关键过程、根本原因分析
Host未建立映射关系,可以通过增加代理配置解决。
结论、解决方案及效果
- 打开SampleOAuth2ClientApplicationTests.java文件。
vim ./spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java
- 按“i”进入编辑模式,修改文件中如下内容。
- 在第20行下面新增如下内容。
import java.util.Properties;
- 从第39行开始插入如下代码。
static { Properties props = System.getProperties(); props.put("http.proxyHost", "127.0.0.1"); props.put("http.proxyPort", "3128"); props.put("https.proxyHost", "127.0.0.1"); props.put("https.proxyPort", "3128"); }
其中,127.0.0.1和3128分别表示代理主机的IP地址和端口,操作时请需要根据实际代理环境配置。
请使用:set list检查格式。不能出现空格,请使用Tab作为代码缩进。
- 在第20行下面新增如下内容。
- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 重新编译Spring Boot。
父主题: 故障排除