英文:
Springboot Manual JAR not running properly
问题
我在Springboot中开发了一个REST API端点,当我访问以下地址时显示一个问候语:
localhost:8081/hello
我自信地将其导出为一个"fat jar"(独立应用程序),使用以下命令:
mvn clean install
现在,问题是当我访问相同的"/hello" URL端点时,我得到了这个错误:
Whitelabel错误页面
此应用程序没有针对/error的显式映射,所以您正在将其视为回退选项。
星期五,2020年10月23日09:15:15 PST
发生了意外错误(类型=未找到,状态=404)。
到底是怎么回事?
我确保在pom.xml文件中指定了我的主类。
我正在使用SpringToolSuite 4 IDE。
英文:
I developed a REST API endpoint in Springboot which displays a greeting when I access:
localhost:8081/hello
Feeling confident I export it as a 'fat jar' (standalone app) using
mvn clean install
Now, the problem is when I access the same '/hello' URL endpoint, I get this:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Oct 23 09:15:15 PST 2020
There was an unexpected error (type=Not Found, status=404).
What the hell happened?
I made sure I specifed my main class in the pom.xml file.
I am using SpringToolSuite 4 IDE.
答案1
得分: 1
我认为Baeldung文章中的指南可以帮助你,我会进行总结并添加我的观点:
-
确保拥有以下依赖项:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.0.1.RELEASE</version> </dependency> </dependencies> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.0.1.RELEASE</version> </plugin> </plugins>
-
为确保准确性,请指定你的主类,例如:
<start-class>com.microservices.MyMainClass</start-class>
-
确保在正确的目录下执行以下命令:
mvn clean install
-
如果你想将其打包为“WAR”文件,使用以下代码:
<packaging>war</packaging>
在“project”属性内部添加。
英文:
I think the guide by Baeldung article can help you, I'll summarize and add my own:
-
Make sure to have these dependencies:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.0.1.RELEASE</version> </dependency> </dependencies> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.0.1.RELEASE</version> </plugin> </plugins> ```
-
Just to be sure specify your main class like:
<start-class>com.microservices.MyMainClass</start-class>
-
Make sure you are executing
'mvn clean install'
on the correct directory -
If you want to package it as 'WAR' file instead, use
<packaging> war </packaging>
inside the "project" properties.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论