zoukankan      html  css  js  c++  java
  • 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的方式是不一样的

  • 相关阅读:
    通过源码安装PostgresSQL
    mysql 8.0.16 单主 mgr搭建
    美团点评SQL优化工具SQLAdvisor开源快捷部署
    通过springboot 去创建和提交一个表单(七)
    在springboot中验证表单信息(六)
    调度任务(五)
    接收上传的multi-file的文件(四)
    消费Restful的web服务(三)
    关于RabbitMQ服务器整合(二)
    在springboot中用redis实现消息队列
  • 原文地址:https://www.cnblogs.com/yi1036943655/p/11237990.html
Copyright © 2011-2022 走看看