美文网首页
springboot - 打war包部署tomcat

springboot - 打war包部署tomcat

作者: 一点温柔 | 来源:发表于2020-05-06 19:45 被阅读0次

step1: pom文件增加build属性

<build>
    <finalName>code-tools</finalName>
    <plugins>
        <!--springboot 打包-->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <includeSystemScope>true</includeSystemScope>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!--project jdk compire-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>

        <!--如果不是打成war包,这段代码需要注释掉-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <!--如果想在没有web.xml文件的情况下构建WAR,请设置为false。-->
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>

    </plugins>

</build>

step2: 移除springboot自带的tomcat

去掉springboot-tomcat内部插件,并且添加tomcat-servlet支持

<!--springboot start-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!--移除嵌入式tomcat插件,如果不是外部tomcat启动,需要注释掉-->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

step3: 设置打包文件类型

//在打包的项目中修改打包格式
<packaging>war</packaging>

step4: 启动类处理


修改springboot启动类,继承SpringBootServletInitializer

/**
 * @author py
 * @date 2018/11/25 10:17 PM.
 */
@EnableTransactionManagement
@SpringBootApplication
public class GenerateApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(GenerateApplication.class, args);
    }

    @Override//为了打包springboot项目
    protected SpringApplicationBuilder configure(
            SpringApplicationBuilder builder) {
        return builder.sources(this.getClass());
    }

}

end......

相关文章

网友评论

      本文标题:springboot - 打war包部署tomcat

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