SpringBoot项目配置多环境env

javaSpringBoot项目多环境配置

为什么

项目里面需要集成测试环境、开发、生产、多云环境,不仅需要application.yml,还需要加载别的config配置文件

故,我需要便捷多环境配置管理

maven Profiles 救命


项目的pom文件管理

复制代码
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
        <!--uuuuu-->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
            <!-- 使用@@站位符,输出Dockerfile至docker文件夹 -->
            <resource>
                <directory>src/main/docker</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*</include>
                </includes>
                <targetPath>../docker</targetPath>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*</include>
                </includes>
                <excludes>
                    <exclude>env/**</exclude>
                    <exclude>.gitkeep</exclude>
                </excludes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/resources/env/${env}</directory>
            </resource>
        </resources>
    </build>
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <env>dev</env>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>

        <profile>
            <id>test</id>
            <properties>
                <env>test</env>
            </properties>
        </profile>
        <profile>
            <id>xrytest</id>
            <properties>
                <env>xrytest</env>
            </properties>
        </profile>
        <profile>
            <id>prd</id>
            <properties>
                <env>prd</env>
            </properties>
        </profile>
    </profiles>
相关推荐
代码漫谈几秒前
Spring Boot 配置指南:约定大于配置的应用
java·spring boot·后端
黎雁·泠崖2 分钟前
二叉树遍历:LeetCode 144 / 94 / 145 之递归 + 分治 + 非递归
java·数据结构·算法·leetcode
凌波粒3 分钟前
LeetCode--347.前 K 个高频元素(栈和队列)
java·数据结构·算法·leetcode
GLPerryHsu3 分钟前
jar包的快速修改和重新发布
java·jar
程序员老邢7 分钟前
【技术底稿 14】通用文件存储组件:SpringBoot 自动装配 + 多存储适配
java·spring boot·后端·阿里云·微服务·策略模式
大连好光景12 分钟前
接口测试入门案例
前端·后端·web
武子康13 分钟前
大数据-269 实时数仓-Flink+HBase+DIM层数据处理实战:构建地区维度数据仓库
大数据·后端·flink
zjneymar14 分钟前
苍穹外卖中一些知识点和问题
java·linux·服务器
Rsun0455116 分钟前
5、Java 原型模式从入门到实战
java·开发语言·原型模式
lxh011317 分钟前
最接近的三数之和
java·数据结构·算法