源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Spring Boot打包war jar 部署tomcat

  • 时间:2022-08-30 01:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Spring Boot打包war jar 部署tomcat
[b]概述[/b] 1.Spring Boot聚合工程打包war部署Tomcat 2.Spring Boot打包Jar,通过Java -jar直接运行. 3.提供完整pom.xml测试项目 至github [b]解决问题[/b] 1.xxxx中没有主清单属性 2.解决没有web.xml而报错 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project provider: Error assembling WAR: webxml attribute is required(or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1] 版本 1.JDK 1.8 2.Spring Boot 1.5.8 3.apache-tomcat-8.5.23 [b]一.[/b] 打包war部署tomcat 1.改写App类 继承SpringBootServletInitializer 2.重写configure方法,返回builder.sources(YouApp.class); 3.添加pom.xml ,如下图 4.修改<packaging>war</packaging> 5.package命令打包 6.可参考 github--> releases--> v0.1 中blog-main-service 它是一个可打包jar且通过java -jar运行的完整项目配置 地址:[url=https://github.com/mmdsyl/BLOG-Microservice/releases]https://github.com/mmdsyl/BLOG-Microservice/releases[/url]
public class ManagerApplication extends SpringBootServletInitializer{
 // for tomcat
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(ManagerApplication.class);
  }
  public static void main(String[] args) throws InterruptedException {
    SpringApplication application = new SpringApplication(ManagerApplication.class);
    //application.setBannerMode(Banner.Mode.OFF);
     application.run(args);
  }
}
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
   </dependency>
  <!--用于解决没有web.xml报错-->
  <plugin>
      <artifactId>maven-war-plugin</artifactId>
       <version>3.0.0</version>
  </plugin>
二. 打包Jar执行运行 1.标准的Application,不要继承SpringBootServletInitializer 2.修改pom,如图 3.package命令打包 4.可参考 github--> releases--> v0.1.1 中blog-main-web ,它是一个可打包war可部署tomcat中的完整配置 地址:[url=https://github.com/mmdsyl/BLOG-Microservice/releases]https://github.com/mmdsyl/BLOG-Microservice/releases[/url]
   <!--打包成jar-->
    <!--https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html-->
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <executions>
        <execution>
          <goals>
            <goal>repackage</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
[b]总结[/b] 以上所述是小编给大家介绍的Spring Boot打包war jar 部署tomcat,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部