Spring Boot(7)war方式打包发布

修改pom.xml文件

jar

修改为

war

添加Tomcat部署依赖包


  org.springframework.boot
  spring-boot-starter-tomcat
  provided

增加ServletInitializer初始化类

package com.moxi;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(MoxiApplication.class);
    }
    
}

上面的MoxiApplication.class是项目自动生成的main启动类:

package com.moxi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MoxiApplication {

    public static void main(String[] args) {
        SpringApplication.run(MoxiApplication.class, args);
    }
}

打包

到项目目录下执行:

mvn package

执行如下:


Spring Boot(7)war方式打包发布_第1张图片
mvn package

target目录下已经生成了war包了:


Spring Boot(7)war方式打包发布_第2张图片
生成war包

部署

最简单的办法,直接复制war包到Tomcat的webapp目录下,启动tomcat。
浏览器加上项目路径访问:http://localhost:8080/moxi-0.0.1-SNAPSHOT/admin/login

Spring Boot(7)war方式打包发布_第3张图片
访问项目

Spring Boot(1)工具安装:

http://www.jianshu.com/p/fb6ed37c90eb

Spring Boot(2)新建Spring Boot工程

http://www.jianshu.com/p/00fd73f515f6

Spring Boot(3)整合Mybatis

http://www.jianshu.com/p/8401e9304fa0

Spring Boot(4)整合thymeleaf

http://www.jianshu.com/p/8d2cc7207fb2

Spring Boot(5)一个极简且完整的后台框架

http://www.jianshu.com/p/923d26d705ed

Spring Boot(6)jar方式打包发布

http://www.jianshu.com/p/9cf6faa8595e

Spring Boot(7)war方式打包发布

http://www.jianshu.com/p/ae170a58f88c

你可能感兴趣的:(Spring Boot(7)war方式打包发布)