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的方式是不一樣的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章