spring-boot分环境打包为war包

1.启动类修改

@EnableSwagger2
@SpringBootApplication
public class CustWebAcApplication extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(CustWebAcApplication.class);
    }

    @Bean
    public RestTemplate restTemplate() {

//        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
//        // 设置超时 10s
//        requestFactory.setConnectTimeout(10000);
//        requestFactory.setReadTimeout(10000);

        RestTemplate restTemplate = new RestTemplate();

        // 使用utf-8字符集
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(Charset.forName("UTF-8")));

        return restTemplate;
    }

}

2.pom配置

    <!-- 多环境打包 start -->
    <profiles>
        <!-- 开发环境配置 -->
        <profile>
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <!-- 测试环境配置 -->
        <profile>
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
        <!-- 正式环境 -->
        <profile>
            <id>online</id>
            <properties>
                <profiles.active>online</profiles.active>
            </properties>
        </profile>
    </profiles>
    <!-- 多环境打包 end -->

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.class</include>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>*.xml</include>
                    <include>*.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/resources/conf/${profiles.active}</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <!--如果想在没有web.xml文件的情况下构建WAR,请设置为false. -->
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

3.打包命令

mvn clean package -Dmaven.test.skip=true -Ptest

4.启动

将war包放到tomcat的webapps下,启动tomcat即可

原文地址:https://www.cnblogs.com/qdwyg2013/p/10305768.html

时间: 2024-08-30 02:03:02

spring-boot分环境打包为war包的相关文章

Spring Boot:项目打包成war并发布到Tomcat上运行

一.修改pom文件 1. 因为SpringBoot中嵌入的有Tomcat,因此要移除嵌入式的Tomcat插件 1 <dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-web</artifactId> 4 <!-- 移除嵌入式Tomcat --> 5 <exclusions> 6 <ex

spring-boot分环境打包为tar包

1.pom配置 <!-- 多环境打包 start --> <profiles> <!-- 开发环境配置 --> <profile> <id>dev</id> <properties> <profiles.active>dev</profiles.active> </properties> <activation> <activeByDefault>true<

将 Spring boot 项目打成可执行Jar包,及相关注意事项(main-class、缺少 xsd、重复打包依赖)

最近在看 spring boot 的东西,觉得很方便,很好用.对于一个简单的REST服务,都不要自己部署Tomcat了,直接在 IDE 里 run 一个包含 main 函数的主类就可以了. 但是,转念一想,到了真正需要部署应用的时候,不可能通过 IDE 去部署啊.那有没有办法将 spring boot 的项目打包成一个可执行的 jar 包,然后通过 java -jar 命令去启动相应的服务呢? 很明显,是有的.下面,我把我自己的实践过程及遇到的问题,一 一说明一下. 首先,把项目的 POM 配置

Spring boot(4)-应用打包部署

摘自: http://blog.csdn.net/hguisu/article/details/51072683 1.Spring Boot内置web spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动.其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat).当然你也可以将项目打包成war包,放到独立的web容器中(Tomcat.weblogic等等),当然在此之前你要对程序入口做简单调整. 对server的几个常用的配

spring boot 依赖环境和项目结构介绍

1.环境介绍 使用 Spring Boot 开发项目需要有两个基础环境和一个开发工具,这两个环境是指 Java 编译环境和构建工具环境,一个开发工具是指 IDE 开发工具. Spring Boot 2.0 要求 Java 8 作为最低版本,需要在本机安装 JDK 1.8 并进行环境变量配置,同时需要安装构建工具编译 Spring Boot 项目,最后准备个顺手的 IDE 开发工具即可. 1.1.构建工具 构建工具是一个把源代码生成可执行应用程序的自动化工具,Java 领域中主要有三大构建工具:A

Spring Boot(十二):Spring Boot 如何测试打包部署

有很多网友会时不时的问我, Spring Boot 项目如何测试,如何部署,在生产中有什么好的部署方案吗?这篇文章就来介绍一下 Spring Boot 如何开发.调试.打包到最后的投产上线. 开发阶段 单元测试 在开发阶段的时候最重要的是单元测试了, Spring Boot 对单元测试的支持已经很完善了. 1.在 pom 包中添加 spring-boot-starter-test 包引用 <dependency> <groupId>org.springframework.boot&

前端自动分环境打包(vue和ant design)

现实中的问题:有时候版本上线的时候,打包时忘记切换环境,将测试包推上正式服务器,那你就会被批了. 期望:在写打包的命令行的时候就觉得自己在打包正式版本,避免推包时候的,不确信自己的包是否正确. 既然有了期望,那么就要开始百度如何去实现呢. 下面先开始介绍ant design的方法: ant design的打包工具是roadhog,那么从roadhog下手. 在roadhog文档中,发现define的配置可以传递给代码. 在ant design pro的issue中搜索中,发现环境变量的配置. 我

Vue项目分环境打包的实现步骤

转:https://blog.csdn.net/xinzi11243094/article/details/80521878 方法一:亲测真的有效 在项目开发中,我们的项目一般分为开发版.测试版.Pre版.Prod版.Vue-cli的默认环境一只有dev和prod两个,之前每次要发布测试版或Pre版都是修改了源码中API地址后打包,这样很麻烦.如果能根据不同环境打包就完美了.网上搜集了许多资料,现在可以分环境打包程序了,至于怎么打,接着住下看吧. 第1步:安装cross-env 在项目目录下运行

spring boot 开发环境搭建(Eclipse)

Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 spring boot 连接Mysql spring boot配置druid连接池连接mysql spring boot集成mybatis(1) spring boot集成mybatis(2) – 使用pagehelper实现分页 spring boot集成mybatis(3) – mybatis ge