SpringBoot 部署war包

1、修改启动类

修改前:

package com.rsi.rc.ae;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
@EnableDiscoveryClient
@EnableCaching // 启用数据缓存
@ComponentScan(value = "com.rsi.rc")
@EnableFeignClients("com.rsi.rc")
@EnableAsync
@EnableScheduling
public class App {

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

修改后:

package com.rsi.rc.ae;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
@EnableDiscoveryClient
@EnableCaching // 启用数据缓存
@ComponentScan(value = "com.rsi.rc")
@EnableFeignClients("com.rsi.rc")
@EnableAsync
@EnableScheduling
public class App extends SpringBootServletInitializer {

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

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

2、修改pom文件

<packaging>war</packaging>
    <!-- 剔除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>
      <!-- 新增外置tomcat依赖 -->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
          <scope>provided</scope>
      </dependency>

3、注意的地方:

1、application.xml 配置文件

  配置的

     server.port

     server.servlet.context-path

  将会失效 因为这些是配置内部tomcat的

2、还有tomcat访问是路径是带项目名的,这个和jar的方式是不一样的

posted @ 2019-07-24 14:53  一只奋斗的猪  阅读(794)  评论(0编辑  收藏  举报