SpringBoot项目打包部署外部JavaEE容器
2017-05-24 16:54
951 查看
前言
springBoot项目开发过程中使用的是内嵌的tomcat,jetty容器,当项目需要发布的时候怎么呢?只需要两步
步骤
修改启动类,继承 SpringBootServletInitializer 并重写 configure 方法
/** * Author: 遇见小星 * Email: tengxing7452@163.com * Date: 17-5-10 * Time: 上午10:40 * Describe: 程序入口 */ @SpringBootApplication @EnableAutoConfiguration public class Mainspringboot extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Mainspringboot.class); }
修改pom.xml文件
<!-- <packaging>jar</packaging> --> <packaging>war</packaging>
tomcat插件依赖包添加生命周期privided
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency>
结束语
SpringBootServletInitializer类implements WebApplicationInitializer接口,而WebApplicationInitializer里有void onStartup(ServletContext var1) 方法void onStartup(ServletContext var1) throws ServletException;
SpringBootServletInitializer 实现了这个onStartup方法,主要在启动容器时负责加载相关配置
public void onStartup(ServletContext servletContext) throws ServletException { this.logger = LogFactory.getLog(this.getClass()); final WebApplicationContext rootAppContext = this.createRootApplicationContext(servletContext); if(rootAppContext != null) { servletContext.addListener(new ContextLoaderListener(rootAppContext) { public void contextInitialized(ServletContextEvent event) { } }); } else { this.logger.debug("No ContextLoaderListener registered, as createRootApplicationContext() did not return an application context"); } }
代码
servletContext.addListener(new ContextLoaderListener(rootAppContext) { public void contextInitialized(ServletContextEvent event) { } });
中ContextLoaderListener实现了ServletContextListener接口,这样就可以通过addListener()的方式将springboot项目下的相关配置进行加载。
相关文章推荐
- 如何将Spring Boot项目打包部署到外部Tomcat
- 使用SpringBoot搭建小型项目,集成mybatis,redis,swagger2,并部署在外部容器中。
- spring-boot项目在外部tomcat环境下部署
- 使用外部容器运行spring-boot项目:不使用spring-boot内置容器让spring-boot项目运行在外部tomcat容器中
- Springboot项目打包成war包,并在tomcat下部署
- spring-boot项目在外部tomcat环境下部署
- springboot项目打包部署时把静态资源打包到jar中、或修改静态资源根目录
- spring-boot项目在外部tomcat环境下部署
- spring-boot项目部署到tomcat容器中
- springboot项目的打包部署(gralde和maven)
- [置顶] Eclipse新建Spring-boot项目,打包部署并输出HelloWord
- spring-boot项目在外部tomcat环境下部署
- spring-boot项目的创建以及部署到外部tomcat的方法
- 使用外部容器运行spring-boot项目:不使用spring-boot内置容器让spring-boot项目运行在外部tomcat容器中
- spring-boot项目在外部tomcat环境下部署
- spring-boot项目在外部tomcat环境下部署
- 把spring-boot项目部署到tomcat容器中
- spring boot -- 多个spring boot 项目部署到同一个web 容器
- spring-boot项目在外部tomcat环境下部署
- Spring Boot项目的打包和部署