springboot 项目打包部署

项目打包

spring boot 打war包。基本步骤

  1. 修改pom文件,jar 中jar改成war。

  2. 修改web 依赖 去掉内嵌的tomcat。


<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

  1. 修改Application.java 文件
// 继承SpringBootServletInitializer
public class Application  extends SpringBootServletInitializer{
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

// 重写方法
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class applicationClass = Application.class;
}
  1. 这个时候如果直接点击运行按钮的话,会出错,这是Idea的bug,需要mvn spring-boot:run一遍就好了。然后打war包。

3.上传

上传
scp ~/Desktop/demo.war [email protected]:/usr/java/tomcat/apache-tomcat-8.5.15/webapps/

4. 访问

在浏览器中输入http:x.x.x.x/demo/就可以访问了。


JDK,1.8
作者:匹斯克
链接:https://www.jianshu.com/p/aa337ff374ec
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

猜你喜欢

转载自blog.csdn.net/wangbo54979/article/details/79832301
今日推荐