我使用 Spring rest 和 Spring boot 创建了一个 rest api。当我尝试将它部署到 linux 服务器上的 tomcat 上时,出现以下错误:
rror during ServletContainerInitializer processing
javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:160
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.server.ResourceConfig
我正在遵循 tomcat 的确切 Spring 引导说明。我的问题是,我没有为我的应用程序 (api) 使用与 Jersey 相关的任何内容,那么它为什么要寻找与 Jersey 相关的代码,以及如何修复它。
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
Controller 代码:
@RestController
@RequestMapping("/rest/cmscontent")
public class BatchController {
最佳答案
如果将 spring-boot-starter-web
作为依赖项添加到 POM 文件中,
它将自动包含嵌入式 Web 容器(默认为 Tomcat)。
因此,直接执行 JAR 即可,无需将其部署到任何 Web 容器。
关于spring boot rest tomcat部署报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38153372/