打成jar直接运行比较简单,这里特别说明的是打成war包,部署在外部的tomcat方式:

1、修改启动代码

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @SpringBootApplication
@EnableAutoConfiguration
@ComponentScan("com.xx.xx")
@Controller
// mapper 接口类扫描包配置
public class Application extends SpringBootServletInitializer { @RequestMapping("/")
String home() {
return "index";
} @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
} public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}

2、修改pom.xml

<packaging>war</packaging>

去除一些可能冲突的配置项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<version>1.5.1.RELEASE</version>
</dependency>

增加servlet(可能不是必须的)

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
</dependency>

tomcat外部依赖:

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

war包名称:

<finalName>ROOT</finalName>

防止没有web.xml报错:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

spring boot 打包的更多相关文章

  1. spring boot (2):spring boot 打包tomcat、tomcat 部署多个项目、服务器部署项目SSL 设置(阿里云)

    一.spring boot 内置tomcat配置https: 关于自签名证书可以看下上一篇 spring boot1 更详细的可以看转载 https://www.jianshu.com/p/8d4ab ...

  2. Spring Boot打包war jar 部署tomcat

    概述 1.Spring Boot聚合工程打包war部署Tomcat 2.Spring Boot打包Jar,通过Java -jar直接运行. 3.提供完整pom.xml测试项目 至github 4.项目 ...

  3. Spring Boot打包总结

    环境配置信息 -** JDK 1.8 -** Spring Boot 1.5.3.RELEASE -** IDE: STS 3.4 Spring Boot下打包过程 基于STS创建Spring boo ...

  4. Spring Boot 打包成的可执行 jar ,为什么不能被其他项目依赖?

    前两天被人问到这样一个问题: "松哥,为什么我的 Spring Boot 项目打包成的 jar ,被其他项目依赖之后,总是报找不到类的错误?" 大伙有这样的疑问,就是因为还没搞清楚 ...

  5. 一些坑 Java 执行命令行命令 Spring Boot 打包为jar ResourceUtils.getFile 等出现的问题

    Java 执行命令行命令 这个没技术含量的东西耗费了我半个多小时 String command = ....; Process process = Runtime.getRuntime().exec( ...

  6. spring boot打包以及centos下部署

    spring boot打包以及部署 一.打包 springboot的打包方式有很多种.有打成war的,有打成jar的,也有直接提交到github,通过jekins进行打包部署的.这里主要介绍如何打成j ...

  7. spring/boot 打包,资源/配置/业务文件分离

    spring/boot打包,将业务jar包和资源配置文件进行分离打包,打包后的资源在target/release文件夹下面 注意:添加以下配置后,注意修改自己的入口类 <!--相关编译打包依赖- ...

  8. Spring Boot打包部署

    date: 2018-11-19 15:30:11 updated: 2018-11-21 08:28:37 Spring Boot打包部署 第一种方式 打包成jar包部署在服务器上 1.1 添加插件 ...

  9. spring boot 打包war后 部署到外部 tomcat 的具体正确操作【包括修改端口 与 去除请求路径的工程名】

    1.前言 工程做好了,总不能放在idea运行吧?不然怎么把项目放到云服务器呢?[这一篇随笔不讲解发布的云服务器的操作,在其他随笔有详细记载.] 解决的方案是把springboot 工程 打包成war文 ...

  10. docker + spring boot 打包 部署。

    docker 安装 什么的 就不一一介绍了 不会安装百度一找一堆. 我这直接上代码. 首先你要有个spring boot项目. 然后打包.打包很简单 我打包的是 jar文件.直接在pom.xml文件里 ...

随机推荐

  1. Linux下汇编语言------计算n的阶乘

    用高级语言比方C语言写个阶乘非常easy,那如今就来熟悉下Linux使用AT&T汇编格式写一个程序来计算阶乘吧 写法一是 使用跳转指令实现.写法二是使用函数来实现 约定:本程序没有将结果打印在 ...

  2. MySQL索引使用:字段为varchar类型时,条件要使用''包起来

    结论: 当MySQL中字段为int类型时,搜索条件where num='111' 与where num=111都可以使用该字段的索引.当MySQL中字段为varchar类型时,搜索条件where nu ...

  3. Android无线测试之—UiAutomator UiSelector API介绍之六

    对象搜索—类名与包名 一.类名属性定位对象 返回值 API 描述 UiSelector calssName(String className) 完整类名匹配 UiSelector calssNameM ...

  4. docker学习笔记(2) 构建镜像

    一.手动构建一个简单镜像 我们以构建nginx的docker镜像为例:手动构建镜像 docker pull centos    安装基础镜像docker run --name mynginx -it ...

  5. java.lang.ClassFormatError: Truncated class file

    之前跑的很好的程序,因为我本地IDE出了问题的原因,倒是编译的错误的class文件,结果点击的时候报这样的错误,后来重新clean了工程,重新打包解压启动,问题依旧. 解决办法: 把tomcat的wo ...

  6. Introduction to Mathematical Thinking - Week 9 评论答案2

    根据 rubic 打分. 1. 我认为,如果说明 m, n 是自然数,所以最小值是 1 会更清楚.所以 Clarity 我给了 3 分.其他都是 4 分,所以一共是 23 分. 2.  我给出的分数 ...

  7. 分布式缓存的一致性Hash算法 2 32

    w 李智慧

  8. HNOI2019爆零记

    HNOI2019真-爆零祭 我怎么这么菜QAQ day-37 从学科溜过来搞OI. 班主任一直在谈论我退役的事情,这就是NOIP挂分的后果...说我没考好就找理由,人家xxxxxxx可不是xxxxxx ...

  9. 内置函数:min 用法

    内置函数:min 用法 源码 def min(*args, key=None): # known special case of min """ min(iterable ...

  10. pymysql连数据库简单版

    # 导入模块 import pymysql # 连接数据库 mysql_conn = pymysql.connect(host="127.0.0.1", port=3306, us ...