spring boot 依赖的子模块里的配置文件如何实现多环境配置

无畏地主 发布于 2019/11/22 14:19
阅读 142
收藏 1

如题,rest模块依赖service模块,service模块有独立的配置文件,那么这个service里的文件如何实现多环境配置?求科普

加载中
1
际宇人
际宇人

最外层pom.xml配置

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <filters.env>dev</filters.env>
                <profiles.active>src/main/resource-dev</profiles.active>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <filters.env>prod</filters.env>
                <profiles.active>src/main/resource-prod</profiles.active>
            </properties>
        </profile>
    </profiles>

子项目pom.xml

<build>
<plugins>
<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<id>default-resources</id>
						<phase>validate</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>target/classes</outputDirectory>
							<useDefaultDelimiters>false</useDefaultDelimiters>
							<delimiters>
								<delimiter>#</delimiter>
							</delimiters>
							<resources>
								<resource>
									<directory>src/main/resources/</directory>
									<filtering>true</filtering>
								</resource>
								<resource>
									<directory>src/main/resources-${filters.env}</directory>
									<filtering>false</filtering>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
</plugins>
<!-- 定义资源目录 -->
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<excludes>
					<exclude>static/**</exclude>
				</excludes>
			</resource>
			<resource>
				<directory>${profiles.active}</directory>
			</resource>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
					<include>static/**</include>
				</includes>
				<filtering>false</filtering>
			</resource>
		</resources>
	</build>
</build>

 

无畏地主
无畏地主
感谢,我这边用include替代了,具体就是在active中单独配置下某个配置项。
返回顶部
顶部