简体   繁体   English

运行 Spring Boot JAR 应用程序不会使用浏览器打开 URL(https://localhost:8080/)

[英]Running a Spring Boot JAR Application does not open a URL(https://localhost:8080/) with a browser

I have a Spring Boot JAR Application.我有一个 Spring Boot JAR 应用程序。 When I run it, no browsers automatically show https://localhost:8080/ .当我运行它时,没有浏览器自动显示https://localhost:8080/ But typing manually the mentioned URL works fine, and the application runs.但是手动输入提到的 URL 工作正常,并且应用程序运行。

@SpringBootApplication
@ImportResource({ "classpath:applicationContext.xml" })
public class StockMaintenanceSystemApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(StockMaintenanceSystemApplication.class, args);
    }

}

Do I need to set the URL(https://localhost:8080/) anywhere?我需要在任何地方设置URL(https://localhost:8080/)吗? If not, please correct my code.如果没有,请更正我的代码。

If I understand correctly, you mean that the browser doesn't open a new tab when you start a spring boot application.如果我理解正确,您的意思是当您启动 spring 启动应用程序时,浏览器不会打开新选项卡。

If that is the case, it shouldn't open a new tab, it simply starts a service on your pc, you need to navigate to the address manually.如果是这种情况,它不应该打开一个新选项卡,它只是在您的 PC 上启动一项服务,您需要手动导航到该地址。 It is simply not something that spring boot does.这不是 spring boot 所做的事情。

When you build the jar file and run it, it will not automatically open the browser for you.当您构建 jar 文件并运行它时,它不会自动为您打开浏览器。 The file jar is used when deploying on the server environment, this is completely different from the developer environment you're still used to, where when you use the IDE, your job is to just click the "run button", the IDE will build the jar file, run it and automatically open the browser for you. jar 文件是在服务器环境部署时使用的,这和你还习惯的开发者环境完全不同,你在使用 IDE 的时候,你的工作就是点击“运行按钮”,IDE 就会构建jar 文件,运行它并自动为您打开浏览器。

The solution for you here is you can write function that execute shell command like that and call it on main function.在这里,您的解决方案是您可以编写像这样执行 shell 命令的函数并在main函数上调用它。 The shell command can be chrome.exe localhost:8080 shell 命令可以是chrome.exe localhost:8080

Opening a browser after running your application is IDE 's responsibility.运行应用程序后打开浏览器是IDE的责任。 IDEs can only open a browser when you package the application as a WAR file, configure an application server, like Tomcat , and restart the container via IDE. IDE 只能在将应用程序打包为WAR文件、配置应用程序服务器(如Tomcat )并通过 IDE 重新启动容器时才能打开浏览器。

So if you package the application as JAR file, it is necessary to open a web browser and type the desired link( localhost:8080 ).因此,如果将应用程序打包为JAR文件,则需要打开 Web 浏览器并键入所需的链接( localhost:8080 )。 But there are some tricks to cope with this situation.但是有一些技巧可以应对这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM