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

  • 相关阅读:
    经典sql面试题(学生表_课程表_成绩表_教师表)
    69道Spring面试题及答案
    Spring常见面试题
    Java基础面试题及答案(六)
    Java基础面试题及答案(五)
    maven工程,java代码加载resources下面资源文件的路径
    oracle的事务级别
    JMeter测试HBase
    JMeter测试clickhouse
    JMeter入门
  • 原文地址:https://www.cnblogs.com/yi1036943655/p/11237990.html
Copyright © 2011-2022 走看看