美文网首页coder
Springboot打包(一) jar包

Springboot打包(一) jar包

作者: S拒绝拖延 | 来源:发表于2019-07-05 14:41 被阅读0次

    1.配置server端口:

    server:
        port: 8080
    

    2.在Maven中指定启动类,打包方式

    <packaging>jar</packaging>
    
    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <mainClass>com.example.XXX.XXX.DemoApplication</mainClass>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    

    3.在启动类当中加上extends SpringBootServletInitializer并重写configure方法

    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;
    
    @SpringBootApplication
    public class SpringDemoApplication extends SpringBootServletInitializer{
    
        public static void main(String[] args) {
            SpringApplication.run(SpringDemoApplication .class, args);
        }
    
        @Override//为了打包springboot项目
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            return builder.sources(this.getClass());
        }
    }
    

    4.运行mvn clean 再 mvn install

    相关文章

      网友评论

        本文标题:Springboot打包(一) jar包

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