a1053646895
___鑖视
采纳率0%
2021-03-03 16:25

maven多模块多环境统一配置信息

我想项目层级为:a > b > c

a 和 b packaging 为  pom,c默认。

在a项目配置:

<profiles>
        <profile>
            <id>dev</id>
            <properties>
                <spring.profiles.active>dev</spring.profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <spring.profiles.active>test</spring.profiles.active>
            </properties>
        </profile>
        <profile>
            <id>pro</id>
            <properties>
                <spring.profiles.active>pro</spring.profiles.active>
            </properties>
        </profile>
    </profiles>
<build>
        <filters>
            <filter>src/main/filters/filter-${spring.profiles.active}.properties</filter>
        </filters>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>utf-8</encoding>
                    <delimiters>
                        <delimiter>@</delimiter>
                        <delimiter>${*}</delimiter>
                    </delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                        <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                        <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
        </plugins>
    </build>

filter-dev.properties:

jdbc.url=127.0.0.1:3306/test

在c的application.yml里面引用

spring.datasource.url=@jdbc.url@

引入失败,项目无法正常启动,这是问1。

 

问2:

在build里面删除filters, 在profiles加入

<profile>
    <id>dev</id>
    <properties>
        <spring.profiles.active>dev</spring.profiles.active>
        <jdbc.url>127.0.0.1:3306/test</jdbc.url>
    </properties>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
</profile>

并且在b和c模块的parent加上<relativePath/>,就能成功引入。但是加上后不能mvn clean和install。

请教各位大大

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

为你推荐