最近一段时间一直在研究和学习springboot,感觉其十分便利好用。以前使用spring搭建项目都整好多繁琐的配置,使用了springboot后这些繁琐的配置统统都不要了。但就是对springboot部署的方式感觉有点不爽,还是比较喜欢打包成war来进行部署。

  在spring中有这样一个类:org.springframework.web.SpringServletContainerInitializer,阅读该类的注释发现该类的作用是使用编程方式的替代web.xml的。其原理就在于该类位于spring-web-xxx.jar中的META-INF/services有一个遵照java spi规范的文件,在支持servlet 3以上版本的j2ee容器中会读取该SPI服务的实现类SpringServletContainerInitializer。springboot已经为我们扩展了该类SpringBootServletInitializer,但是该类是一个抽象类,抽象类无法被实例化因此我们需要创建一个类并继承该类。

 package com.torlight;

 import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import javax.servlet.ServletContext;
import javax.servlet.ServletException; /**
* Created by acer on 2017-05-24.
* {@code TorlightSpringBootServletInitializer}继承于SpringBootServletInitializer 被 SpringServletContainerInitializer
* 使用
* @author acer
* @since 2017.05.24
*/
@Order(Ordered.HIGHEST_PRECEDENCE+)
@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class TorlightSpringBootServletInitializer extends SpringBootServletInitializer{ private static final Logger logger= LoggerFactory.getLogger(TorlightSpringBootServletInitializer.class); @Override
public void onStartup(ServletContext servletContext) throws ServletException {
if(logger.isInfoEnabled()){
logger.info("TorlightSpringBootServletInitializer is startup");
}
super.onStartup(servletContext);
}
}

将pom.xml文件中packaging由jar改成war

由于打包成war独立部署,将spring-boot-starter-tomcat 的范围改成provided

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

移除spring-boot-maven-plugin maven插件

<!--
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin> --> 将静态文件按照war中的规范存放到webapp目录 完成上面的步骤后,执行maven打包命令将输出的war部署j2ee容器中

最新文章

  1. easyui Datagrid查询报错Uncaught TypeError:Cannot read property &#39;length&#39; of undefined
  2. Arduino 极速入门系列 - 光控灯(3) - 光敏电阻、与电阻分压那些事
  3. 理解jquery的$.extend()、$.fn和$.fn.extend()
  4. CSS 单行溢出文本显示省略号...的方法(兼容IE FF)(转)
  5. C++动态内存管理之shared_ptr、unique_ptr
  6. 什么情况下include_path不起作用?
  7. 暑假集训(5)第一弹——— Super Jumping! Jumping! Jumping!(hdu1087)
  8. SQL Server 扩展事件(Extented Events)从入门到进阶(1)——从SQL Trace到Extented Events
  9. artDialog.js的使用
  10. HDU 5875 Function(ST表+二分)
  11. [Android]SDK安装
  12. 高级软件工程2017第5次作业—— 团队项目:需求改进&amp;系统设计
  13. 安卓高级8 SurfaceView案例二 自定义相机
  14. java接口变量问题
  15. Ubuntu下录制和制作Gif图片--实战版
  16. Java消息中间件入门笔记 - ActiveMQ篇
  17. Spring注解方式配置Redis
  18. ssh访问服务器端visdom
  19. 【译】ASP.NET Identity Core 从零开始
  20. at com.mysql.jdbc.SQLError.createSQLException

热门文章

  1. git 从新的git 库中拉取---变换git地址用;
  2. 配置pdo 的用户和密码,
  3. Ubuntu+NDK编译支持HTTPS的libcurl
  4. 简单实现VUE的双向数据绑定
  5. JS函数表达的几种写法
  6. MyBatis操作oracle的一些问题加载
  7. 2017 济南精英班 Day1
  8. LightOJ 1364 树形DP
  9. King&#39;s Sanctuary(简单几何)
  10. JS DOM之表格操作