• spring boot 打包


    打成jar直接运行比较简单,这里特别说明的是打成war包,部署在外部的tomcat方式:

    1、修改启动代码

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.support.SpringBootServletInitializer;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @SpringBootApplication
    @EnableAutoConfiguration
    @ComponentScan("com.xx.xx")
    @Controller
    // mapper 接口类扫描包配置
    public class Application extends SpringBootServletInitializer {
    
        @RequestMapping("/")
        String home() {
            return "index";
        }
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Application.class, args);
        }
    }

    2、修改pom.xml

    <packaging>war</packaging>

    去除一些可能冲突的配置项:
    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-databind</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>log4j-over-slf4j</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-logging</artifactId>
                    </exclusion>
                </exclusions>
                <version>1.5.1.RELEASE</version>
            </dependency>

    增加servlet(可能不是必须的)

    <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>4.0.0</version>
            </dependency>

    tomcat外部依赖:

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <version>1.4.7.RELEASE</version>
                <scope>provided</scope>
            </dependency>

    war包名称:

    <finalName>ROOT</finalName>


    防止没有web.xml报错:
    <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
  • 相关阅读:
    Spring Boot下的一种导入Excel文件的代码框架
    Spring Boot下的一种导出CSV文件的代码框架
    Spring Boot下的一种导出Excel文件的代码框架
    使用系统参数表,提升系统的灵活性
    折纸效果! Cocos Creator 3.0
    弹性跟随相机!3D入门教程!
    dotnet OpenXML 读取 PPT 主序列进入退出强调动画
    dotnet C# 调用委托的 GetInvocationList 的对象分配
    WPF 下拉框选项做鼠标 Hover 预览效果
    WPF 后台代码做 TranslateTransform 的动画
  • 原文地址:https://www.cnblogs.com/tengpan-cn/p/7927671.html
Copyright © 2020-2023  润新知