springboot部署
jar方式部署
直接安装运行jar即可
war方式部署到tomcat
war部署到tomcat的坑:
1.修改启动类,继承SpringBootServletInitializer并重写configure方法: package com.imux.wxsell; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; //没有数据源时添加 exclude = {DataSourceAutoConfiguration.class} @SpringBootApplication //@MapperScan(basePackages = "com.imux.xwsell.dao")//mybatis接口包 public class WxsellApplication extends SpringBootServletInitializer { /**重写configure方法--外部tomcat部署*/ @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(WxsellApplication.class); } public static void main(String[] args) { SpringApplication.run(WxsellApplication.class, args); } } -------------------------------------------------------------------------------------------------- 2.修改pom.xml文件 <packaging>jar</packaging> 改为: <packaging>war</packaging> -------------------------------------------------------------------------------------------------- 3.屏蔽内嵌tomcat <!--去除内嵌tomcat--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> -------------------------------------------------------------------------------------------------- 4.由于本项目中使用了websocket,并且在WebSocketConfig中将ServerEndpointExporter指定给Spring管理,当使用外部tomcat容器时,部署后ServerEndpoint是需要Tomcat直接管理才能生效的,所以会报错误信息:<<<Failed to register @ServerEndpoint class>>>,解决方法: 将:WebSocketConfig.java类中的内容全部注释掉即可: /* @Component public class WebSocketConfig { @Bean public ServerEndpointExporter serverEndpointExporter() { return new ServerEndpointExporter(); } } */参考文档
springboot官方文档: