我想为我的使用特定JVM参数的spring boot应用程序创建一个测试,我希望JVM参数仅与该测试一起使用。
这可能吗?我的目标是仅为一个测试设置代理,因此,如果有另一种方法可以实现这一目标,请提出建议。
如果使用的是IntelliJ Idea,则可以从运行/调试配置-> VM选项中传递参数以进行测试。如果您使用的是Maven,则可以在surefire-plugin配置中传递参数:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1G</argLine>
</configuration>
</plugin>
并且请记住,Maven选项将覆盖Idea的默认值(如果已设置)。
我通过在类中添加静态块并设置系统属性来解决此问题:
static {
System.setProperty("http.proxyHost", "myproxyserver.com");
System.setProperty("http.proxyPort", "80");
System.setProperty("https.proxyHost", "myproxyserver.com");
System.setProperty("https.proxyPort", "80");
}