美文网首页
springboot配置多环境运行文件

springboot配置多环境运行文件

作者: engineer_tang | 来源:发表于2020-02-28 09:05 被阅读0次

    第一步:在main文件目录下创建文件夹env/prod、env/dev、env/test,并在文件夹下分别创建文件application.yml
    第二步:在pom.xml增加配置信息

    <profiles>
            <profile>
                <id>dev</id>
                <properties>
                    <package.environment>dev</package.environment>
                </properties>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <build>
                    <resources>
                        <resource>
                            <directory>src/main/resources</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <filtering>true</filtering>
                        </resource>
                        <resource>
                            <directory>src/main/env/${package.environment}</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <filtering>true</filtering>
                        </resource>
                    </resources>
                    <finalName>${project.artifactId}</finalName>
                </build>
            </profile>
            <profile>
                <id>prod</id>
                <properties>
                    <package.environment>prod</package.environment>
                </properties>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>
                <build>
                    <resources>
                        <resource>
                            <directory>src/main/resources</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <filtering>true</filtering>
                        </resource>
                        <resource>
                            <directory>src/main/env/${package.environment}</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <filtering>true</filtering>
                        </resource>
                    </resources>
                    <finalName>${project.artifactId}</finalName>
                </build>
            </profile>
            <profile>
                <id>test</id>
                <properties>
                    <package.environment>test</package.environment>
                </properties>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>
                <build>
                    <resources>
                        <resource>
                            <directory>src/main/resources</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <filtering>true</filtering>
                        </resource>
                        <resource>
                            <directory>src/main/env/${package.environment}</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <filtering>true</filtering>
                        </resource>
                    </resources>
                    <finalName>${project.artifactId}</finalName>
                </build>
            </profile>
        </profiles>
    

    相关文章

      网友评论

          本文标题:springboot配置多环境运行文件

          本文链接:https://www.haomeiwen.com/subject/qklkhhtx.html