What I am trying to do is, open home page link in a browser once my spring boot application started.
I have two profiles local
& prod
. Using local
for now.
I am trying to read server address from properties file as @Value("${server.address}") private static String serverAddress;
but don't understand what's going wrong.
@SpringBootApplication
public class WebWalletApplication {
@Value("${server.port}")
private static String serverPort;
@Value("${server.address}")
private static String serverAddress;
public static void main(String[] args) throws URISyntaxException {
SpringApplication.run(WebWalletApplication.class, args);
openHomePage();
}
private static void openHomePage() throws URISyntaxException {
System.out.println("serverAddress: " + serverAddress);
String url = "https://" + serverAddress + ":" + serverPort + "/wallet/secure/home";
URI homepage = new URI(url);
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(homepage);
} catch (IOException e) {
e.printStackTrace();
}
} else {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
application.properties
spring.profiles.active=local
application-local.properties
server.address=192.168.1.79 server.port=8084