美文网首页
将SpringBoot打成war包并部署

将SpringBoot打成war包并部署

作者: 苏菜鸡 | 来源:发表于2018-05-08 17:43 被阅读0次

Maven中的设置

将打包类型jar

<packaging>jar</packaging>

修改为war

<packaging>war</packaging>

将以下代码

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

替换为

<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>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <scope>provided</scope>
</dependency>

让程序启动类继承 SpringBootServletInitializer,并重写configure方法,以WebsocketServerApplication为例

@SpringBootApplication
@EnableAutoConfiguration
public class WebsocketServerApplication extends SpringBootServletInitializer {
  public static void main(String[] args) {
    SpringApplication.run(WebsocketServerApplication.class, args);
  }
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(WebsocketServerApplication.class);
  }
}

相关文章

网友评论

      本文标题:将SpringBoot打成war包并部署

      本文链接:https://www.haomeiwen.com/subject/gruwrftx.html