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>
相关推荐
卷福同学5 小时前
【养虾日记】Openclaw操作浏览器自动化发文
人工智能·后端·算法
江湖十年6 小时前
Go 并发控制:sync.Pool 详解
后端·面试·go
xdl25997 小时前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
回到原点的码农7 小时前
Spring Data JDBC 详解
java·数据库·spring
gf13211117 小时前
python_查询并删除飞书多维表格中的记录
java·python·飞书
zb200641207 小时前
Spring Boot 实战:轻松实现文件上传与下载功能
java·数据库·spring boot
一勺菠萝丶7 小时前
Flowable + Spring 集成踩坑:流程结束监听器查询历史任务为空 & 获取不到审批意见
java·数据库·spring
jwn9997 小时前
Spring Boot 整合 Keycloak
java·spring boot·后端
宁波阿成7 小时前
OpenClaw 在 Ubuntu 22.04.5 LTS 上的安装与问题处理记录
java·linux·ubuntu·openclaw·龙虾
mldlds7 小时前
SpringBoot详解
java·spring boot·后端