Spring Boot打包方式

一、JAR

1、创建ServletInitializer类,继承ServletInitializer

package com.test;

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

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return super.configure(builder);
    }

}

2、修改pom.xml打包方式为JAR

<packaging>jar</packaging>

二、WAR

1、创建ServletInitializer类,继承ServletInitializer

package com.test;

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

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(AccountApplication.class);
    }

}

2、修改pom.xml打包方式为JAR

<packaging>war</packaging>

三、包名修改

<build>
  <finalName>Demo</finalName>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

发表评论