美文网首页
Springboot打成war包并在tomcat中运行

Springboot打成war包并在tomcat中运行

作者: 大卵 | 来源:发表于2019-09-25 17:38 被阅读0次
    1. 在pom.xml里设置
      <packaging>war</packaging>

    2.加依赖

     <!--声明spring boot内嵌tomcat的作用范围  在运行时不起作用-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
    

    四、修改启动类

    package com.xyy.medical;
    
    import org.mybatis.spring.annotation.MapperScan;
    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.context.annotation.ComponentScan;
    
    @SpringBootApplication
    @MapperScan("com.xyy.dao")
    @ComponentScan(basePackages = {"com"})
    public class MedicalApplication extends SpringBootServletInitializer {
    
        public static void main(String[] args) {
            SpringApplication.run(MedicalApplication.class, args);
        }
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            // 注意这里要指向原先用main方法执行的Application启动类
            return builder.sources(MedicalApplication.class);
        }
    
    }
    
    

    五、打包部署 mvn clean package

    image.png

    BUILD SUCCESS ~
    打包成功

    image.png

    如果发现打包多了个 original结尾的war包
    把pom文件的 这个注释掉就可以了

      <!--<plugin>-->
                    <!--<groupId>org.springframework.boot</groupId>-->
                    <!--<artifactId>spring-boot-maven-plugin</artifactId>-->
                <!--</plugin>-->
    

    参考了
    https://yq.aliyun.com/articles/319770

    相关文章

      网友评论

          本文标题:Springboot打成war包并在tomcat中运行

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