博客
关于我
问题解决20:SpringBoot2.0打war包 可用
阅读量:680 次
发布时间:2019-03-16

本文共 2632 字,大约阅读时间需要 8 分钟。

Spring Boot 打 War 包 的 完整 应用 指南

在 现代 开发 中,使用 Spring Boot 创建 更高层次 的 应用 架构 已经 成为 主流。 本 文 将 帮助 你 学习 如何 将 Spring Boot 应用 打包 为 WAR 文件 并 部署。此 前 需要 对 Maven 的 基础 知识 有 所了解。

第一步: 配置 Maven POM 文件 打包 WAR

  • 修改 POM 文件中的 包装格式
  • 打开 项目 的 pom.xml 文件, 找到 <packaging> 标签, 将其 修改 为 war。 这 表示 Maven 会 在 打包 时 生成 WAR 文件 而 不是 JAR。

    1. 添加 必要的 Maven 插件
    2. pom.xml 是 Maven 的 工作室, 需要 添加 适当 的 插件 来 完成 WAR 打包。

      an example 配置 示例:
      org.apache.maven.plugins
      maven-compiler-plugin
      1.8
      1.8
      1.8
      org.springframework.boot
      spring-boot-maven-plugin
      version>1.x.x
      com.leeue.App
      app/resources/
      repackage
      org.apache.maven.plugins
      maven-war-plugin
      2.6
      false

      第二步: 修改 主 应用 类

      WAR 文件 的 主 应用 类 通常 需要 配置 SpringBootServletInitializer 以 确保 WAR 文件 可以 正确 启动。

      代码示例:
      import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class App extends SpringBootServletInitializer {    public static void main(String[] args) {        SpringApplication.run(App.class, args);    }    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {        return builder.sources(App.class);    }}

      可选项: 配置 � Motive 和 主oggledClass

      可以 在 configure 方法 中 增加 额外配置:

      @Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {    builder = builder        .motivate("这是一个基于 Spring Boot 的 WAR 包")        .mainClassName("com.leeue.App");    return builder;}

      这 需要 在 pom.xml 中 添加对应 的配置, 确保_Application 可以 正确 找到 主类。

      部署 WAR 文件

      打包 完成 后, WAR 文件 可以 部署 到 应用 服务器 或 Web 足够 的 Environment。

      通常, deploying WAR 文件 需要:

    3. 复制 WAR 文件 到 服务器: 确保 服务器 允许 Tomcat 或其他 Web 服务器 读取 WAR 文件。

    4. 通过 URL 或台 启动应用: 使用 �iren 的服务 URLs 或copy 里 指向文件。

    5. 注意: 如果你 想通过 ./mvnw clean deploy 一键部署, 需要 配置 Maven WAR 插件 的 deploy 目标.


      以上 就是完整的 Spring Boot 打 WAR 包 的 指南. 如果有不明白的地方, 建议 在 实践项目 中 �.getColumnIndex 初始化配置, 这样 可能 更直观.

    转载地址:http://kyeqz.baihongyu.com/

    你可能感兴趣的文章
    Oracle RAC性能调整的方案
    查看>>
    oracle rac集群的东西之QQ聊天
    查看>>
    UML— 用例图
    查看>>
    Oracle Schema Objects——Tables——Table Compression
    查看>>
    oracle scott趣事
    查看>>
    oracle script
    查看>>
    Oracle select表要带双引号的原因
    查看>>
    Oracle SOA Suit Adapter
    查看>>
    Oracle Spatial GeoRaster 金字塔栅格存储
    查看>>
    Oracle spatial 周边查询SQL
    查看>>
    Oracle Spatial空间数据库建立
    查看>>
    UML— 活动图
    查看>>
    oracle sqlplus已停止工作,安装完成客户端后sqlplus报“段错误”
    查看>>
    oracle SQLserver 函数
    查看>>
    oracle sql分组(group,根据多个内容分组)在select之后from之前 再进行select查询,复杂子查询的使用
    查看>>
    UML— 时序图
    查看>>
    Oracle Statspack分析报告详解(一)
    查看>>
    oracle tirger_在Oracle中,临时表和全局临时表有什么区别?
    查看>>
    Oracle Validated Configurations 安装使用 说明
    查看>>
    oracle where 条件的执行顺序分析1
    查看>>