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>
相关推荐
烧烧的酒0.o14 小时前
Java——JavaSE完整教程
java·开发语言·学习
鹏哥哥啊Aaaa14 小时前
15.idea启动报错
java·ide·intellij-idea
计算机毕设VX:Fegn089514 小时前
计算机毕业设计|基于springboot + vue球鞋购物系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
super_lzb14 小时前
VUE 请求代理地址localhost报错[HPM] Error occurred while trying to proxy request
java·spring·vue·springboot·vue报错
Dream_sky分享14 小时前
IDEA 2025中TODO找不到
java·ide·intellij-idea
苏渡苇14 小时前
用 Spring Boot 项目给工厂装“遥控器”:一行 API 控制现场设备!
java·人工智能·spring boot·后端·网络协议·边缘计算
伊甸314 小时前
基于LangChain4j从0到1搭建自己的的AI智能体并部署上线-1
java·langchain·prompt
我待_JAVA_如初恋14 小时前
重装系统后,idea被拦截,突然无法运行
java·ide·intellij-idea
东东51614 小时前
校园短期闲置资源置换平台 ssm+vue
java·前端·javascript·vue.js·毕业设计·毕设
像少年啦飞驰点、14 小时前
零基础入门 Spring Boot:从“Hello World”到独立可运行 Web 应用的完整学习闭环
java·spring boot·web开发·编程入门·后端开发