在tomcat上安装spring启动应用程序
我遵循一个简单的指南,在本地创建了一个基于spring boot的web应用程序,使用嵌入式tomcat,效果很好。下一步,我将尝试将其部署到远程LinuxTomcat服务器上。我首先遵循以下步骤: (1) 更新应用程序的主类以扩展在tomcat上安装spring启动应用程序,tomcat,spring-boot,Tomcat,Spring Boot,我遵循一个简单的指南,在本地创建了一个基于spring boot的web应用程序,使用嵌入式tomcat,效果很好。下一步,我将尝试将其部署到远程LinuxTomcat服务器上。我首先遵循以下步骤: (1) 更新应用程序的主类以扩展SpringBootServletInitializerSpringBootApplication是我以前的主课 public class WebInitializer extends SpringBootServletInitializer { @Overri
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) 更新构建配置,以便project生成war文件而不是jar文件
<packaging>war</packaging>
(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
我的应用程序的正确路径应该是什么?在本地上运行时,它在没有应用程序名称的情况下运行。当我看到服务器catalina.out日志时,没有异常,服务器启动。您可以看到我的答案
答案还包含一个指向演示项目的链接,您可以构建该项目并将其部署到Tomcat
server.context路径
在将war文件部署到外部容器时无效
Tomcat使用war的全名减去
.war
后缀作为应用程序的上下文路径。假设您已将spring-boot-web-0.0.1-SNAPSHOT.war
复制到Tomcat的webapps
目录中,您的应用程序将在处可用。请重试。我想可能有用。谢谢!这是我一直存在的一个很大的疑问:)现在我明白了。是否有机会更改tomcat配置以更改应用程序服务器端点?
http://host:port/springbootdemo
http://host:port/spring-boot-web
http://host:port/spring-boot-web/springbootdemo