【发布时间】:2016-08-10 20:12:39
【问题描述】:
我遵循了一个简单的指南,并使用嵌入式 tomcat 在我的本地创建了一个基于 spring-boot 的 Web 应用程序,它运行良好。下一步我试图将它部署到远程 linux tomcat 服务器上。我首先按照以下步骤操作:
(1) 更新应用程序的主类以扩展SpringBootServletInitializer。 SpringBootApplication是我之前的主班
public class WebInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringBootWebApplication.class);
}
}
@SpringBootApplication
public class SpringBootWebApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootWebApplication.class, args);
}
}
@Controller
public class IndexController {
@RequestMapping("/")
String index(){
return "index";
}
}
(2) 更新构建配置,使项目生成war 文件而不是jar 文件。
<packaging>war</packaging>
(3) 将嵌入式 servlet 容器依赖项标记为已提供。在我刚刚添加了一个spring-boot-starter-web之前我没有这个依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
(4) 我还在application.properties中添加了应用路径
server.context-path = /springbootdemo
在运行 maven-clean 和 maven-install 之后,我得到了我的 spring-boot-web-0.0.1-SNAPSHOT.war,然后将其放入远程服务器中的 tomcat webapp 中,但我得到了 404:
http://host:port/springbootdemo
http://host:port/spring-boot-web
http://host:port/spring-boot-web/springbootdemo
我的应用程序的正确路径应该是什么?在本地运行时,它在 http://localhost:8080/ 上运行,没有应用程序名称。当我看到服务器 catalina.out 日志时,没有异常并且服务器启动。
【问题讨论】:
标签: tomcat spring-boot