美文网首页
SpringBoot打包成war包并部署到tomcat容器中

SpringBoot打包成war包并部署到tomcat容器中

作者: 无至 | 来源:发表于2018-02-05 14:29 被阅读1034次

    1、修改Application类,复写configure方法

    @SpringBootApplication
    @MapperScan("")
    public class Application extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            return builder.sources(Application.class);
        }
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
    }
    

    2、修改pom.xml

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <!-- 移除嵌入式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>
    

    3、打包

    mvn clean package
    

    4、乱码问题。修改tomcat的server.xml配置文件,如下:

    <Connector 
        connectionTimeout="20000" 
        port="8080" protocol="HTTP/1.1" 
        redirectPort="8443" 
        useBodyEncodingForURI="true"/>
    

    相关文章

      网友评论

          本文标题:SpringBoot打包成war包并部署到tomcat容器中

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