美文网首页
springboot 打war包

springboot 打war包

作者: lilac_163 | 来源:发表于2018-11-21 10:48 被阅读0次

    使用版本:

    springboot 2.0.0

    jdk 8

    tomcat 8.50以上

    低版本的tomcat可能会报错

    Invalid byte tag in constant pool : 19

    修改pom.xml

    <packaging>war</packaging>

    <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>

    去掉starter中内嵌的tomcat引用

    增加plugin war

    <build>

            <plugins>

                <plugin>

                    <artifactId>maven-war-plugin</artifactId>

                    <configuration>

                        <warName>${project.name}</warName>

                        <failOnMissingWebXml>false</failOnMissingWebXml>

                    </configuration>

                </plugin>

                <plugin>

                    <groupId>org.springframework.boot</groupId>

                    <artifactId>spring-boot-maven-plugin</artifactId>

                    <version>${spring-boot.version}</version>

                    <executions>

                        <execution>

                            <goals>

                                <goal>repackage</goal>

                            </goals>

                        </execution>

                    </executions>

                </plugin>

                </plugins>

        </build>

    修改代码

    application.source的入参为入口类WebApplication

    @ServletComponentScan

    public class ServletInitializer extends SpringBootServletInitializer {

        @Override

        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

            logger.info("开始启动项目。。。ServletInitializer");

            return application.sources(WebApplication.class);

        }

    }

    相关文章

      网友评论

          本文标题:springboot 打war包

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