通过运行应用程序(直接)启动一个小型 SpringBoot 应用程序,REST 服务 localhost:8080/xyz/a 给出了正确的 JSON 结果。
我通过 IntelliJ 配置了一个 Tomcat 服务器。我添加了此 WAR,其上下文根为“/contextroot”。所以我希望 URL REST 是 localhost:8080/contextroot/xyz/a。这不断收到 404 错误。
你能帮我获得正确的配置或 URL 吗?
有没有办法查看哪些 URL 从 Controller 映射到 URL?或者:我怎样才能更容易地解决这些映射问题(来自 Tomcat)?
在 Maven Pom.xml 中我有:
<groupId>nl.xyz</groupId>
<artifactId>contextroot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>contextroot</name>
<packaging>war</packaging>
内部也是上下文根。
最佳答案
@Jonhib - 感谢您的帮助。
问题是我将 SpringBoot (jar) 应用程序部署为 WAR 的方式。
采取这 3 个步骤将 SpringBoot 标准应用程序更改为可部署的(老式的)WAR。这是必需的,因为我将它与 Angular4 应用程序一起部署。
第 1 步 - 更改标准 SpringBoot 应用程序:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application .class);
}
public static void main(String[] args) {
SpringApplication.run(Application .class, args);
}
}
将构建过程的目标从“jar”更改为“war”。
war 在 pom.xml maven 文件中添加一个新的依赖:
<依赖关系> ... <依赖关系>
org.springframework.boot spring-boot-starter-tomcat <范围>提供范围> 依赖> ...
关于maven - 在 Tomcat 上通过 IntelliJ 部署 Spring Boot(休息服务)war 会出现 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45245230/