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

本文共 2651 字,大约阅读时间需要 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;
      @SpringBootApplication
      public 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 方法 中 增加 额外配置:

      @Override
      protected 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/

    你可能感兴趣的文章
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    no session found for current thread
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    no1
    查看>>
    NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>
    Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
    查看>>
    Node-RED中使用JSON数据建立web网站
    查看>>
    Node-RED中使用json节点解析JSON数据
    查看>>
    Node-RED中使用node-random节点来实现随机数在折线图中显示
    查看>>
    Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
    查看>>