Maven如何设置java中可见的属性

Maven如何设置java中可见的属性,java,spring,maven,Java,Spring,Maven,这是我在pom.xml中的配置文件: <!-- Production Profile --> <profile> <id>production</id> <activation> <property> <name>profile</name> <value>pro

这是我在pom.xml中的配置文件:

<!-- Production Profile -->
    <profile>
        <id>production</id>
        <activation>
            <property>
                <name>profile</name>
                <value>prod</value>
            </property>
        </activation>
        <properties>
            <build.profile.id>prod</build.profile.id>
        </properties>

    </profile>

    <!-- Development Profile -->
    <profile>
        <id>development</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <build.profile.id>dev</build.profile.id>
        </properties>
    </profile>

    <!-- Integration Test Profile -->
    <!-- Use mvn -Dprofile=test -->
    <profile>
        <id>integration-test</id>
        <activation>
            <property>
                <name>profile</name>
                <value>test</value>
            </property>
        </activation>
        <properties>
            <!-- Used to locate the profile specific configuration file -->
            <build.profile.id>test</build.profile.id>
            <!-- Only integration tests are run. -->
            <skip.integration.tests>false</skip.integration.tests>
            <skip.unit.tests>true</skip.unit.tests>
        </properties>
    </profile>
因此,这些技巧允许我使用不同的配置运行我的项目。我还有3个配置属性文件,其中包括:

spring.profiles.active=integration-test
spring.profiles.active=prod
spring.profiles.active=dev
这个配置工作得很好。活动配置文件按我预期的那样更改,例如,当我运行
mvn clean install-Dprofile=test
时,我正在使用
app test.properties
文件,我的活动配置文件是
集成测试


但是这个技巧有一个问题。当有人运行mvn install-Pintegration测试时,活动概要文件是dev而不是integration test。因此,可以运行
mvn安装-pinintegration测试,然后将属性配置文件设置为test???

您不应该在每个环境中使用Maven配置文件。使用Maven可以构建jar/war/ear。不同的环境不应该导致另一个工件。因此,您应该将配置拉到这个工件之外。描述了许多解决此问题的选项。

请尝试
-p+集成测试
选项

当您说活动配置文件是什么时,您是指spring配置文件还是maven配置文件?是的。Spring找不到${profile}的值,这就是为什么选择了默认值“dev”。“您不应该在每个环境中使用Maven概要文件。”,他确实应该这样做,但不是这样:)。正如eis所说,区别在于Spring配置文件不是Maven配置文件。混乱由此而来。
spring.profiles.active=integration-test
spring.profiles.active=prod
spring.profiles.active=dev