欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

maven profile true的作用

程序员文章站 2024-03-22 16:10:16
...

1  在pom.xml中 <!--<filtering>true</filtering>--> 被注释掉

打包时能替换文件名,但是不能替换文件里面的标识符,启动项目时报错。

 

2 在pom.xml中 <filtering>true</filtering>

打包时能替换文件名,也能替换文件里面的标识符:启动时正常
 

------------------------------------------------------------------------------

1  在pom.xml中 <!--<filtering>true</filtering>--> 被注释掉

        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profilesActive>dev</profilesActive>
                <activated_yml>dev</activated_yml>
            </properties>
            <build>
                <resources>
                    <resource>
                        <!--<filtering>true</filtering>-->
                        <directory>src/main/resources</directory>
                        <includes>
                            <include>application.yml</include>
                            <include>application-${activated_yml}.yml</include>
                            <include>logback-dev.xml</include>
                            <include>spring-mvc.xml</include>
                            <include>spring-task.xml</include>
                            <include>mybatis/mapper/*.xml</include>
                            <include>mybatis/mybatis-config.xml</include>
                        </includes>
                    </resource>
                </resources>
            </build>

        </profile>

打包时能替换文件名,但是不能替换文件里面的标识符:

maven profile true的作用

maven profile true的作用

启动项目时报错:

14:37:32.598 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'

 

2 在pom.xml中 <filtering>true</filtering>

        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profilesActive>dev</profilesActive>
                <activated_yml>dev</activated_yml>
            </properties>
            <build>
                <resources>
                    <resource>
                        <filtering>true</filtering>
                        <directory>src/main/resources</directory>
                        <includes>
                            <include>application.yml</include>
                            <include>application-${activated_yml}.yml</include>
                            <include>logback-dev.xml</include>
                            <include>spring-mvc.xml</include>
                            <include>spring-task.xml</include>
                            <include>mybatis/mapper/*.xml</include>
                            <include>mybatis/mybatis-config.xml</include>
                        </includes>
                    </resource>
                </resources>
            </build>

        </profile>

打包时能替换文件名,也能替换文件里面的标识符:启动时正常
maven profile true的作用