java - Springboot 手动 JAR 无法正常运行
问题描述
我在 Springboot 中开发了一个 REST API 端点,当我访问时会显示一个问候语:
localhost:8081/hello
我有信心将其导出为“胖罐”(独立应用程序),使用
mvn clean install
现在,问题是当我访问相同的 '/hello' URL 端点时,我得到了这个:
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).
到底发生了什么?我确保我在 pom.xml 文件中指定了我的主类。
我正在使用 SpringToolSuite 4 IDE。
解决方案
我认为Baeldung文章的指南可以帮助您,我将总结并添加我自己的:
确保具有以下依赖项:
<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>
在“项目”属性中。
推荐阅读
- r - 在数据框中创建新列时,用内置函数替换 R 中的几个 if else 语句
- c# - 如何在 combobox.SelectedItem 中访问 Id 和 Name?
- java - 已签名的 Java 应用程序被 Java 安全性阻止
- android - 无法使用 Android OneDrive Picker 上传(“NoFileSpecified”错误)
- google-app-maker - 如何将日期值从文本框发送到应用程序制造商中的服务器脚本?
- python - 计算行之间的日期差异并按类别Python分组
- docker - Heroku 容器部署为工作人员未启动
- javascript - 如何使用角度 6 中的值解析电子邮件模板的动态元素
- django - 如何使用 manyToMany 和 inlineformset 在 Django 中表示家庭关系?
- python - 尝试在 Python 中重写 C++ 代码时出现问题:删除地图中的项目和“vector.erase(vector.end())”