SpringBoot 根据不同profile选择不同配置

2021-07-14 10:05:29 浏览数 (1)

参考 :https://blog.csdn.net/top_code/article/details/78570047

附上pom的 profiles配置

代码语言:javascript复制
	<build>
		<finalName>${project.artifactId}finalName>
		<resources>
			<resource>
				<directory>src/main/resources/directory>
				<filtering>truefiltering>
			resource>

		resources>


		<plugins>

			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-compiler-pluginartifactId>
				<configuration>
					<encoding>utf-8encoding>
					<source>1.8source>
					<target>1.8target>
				configuration>
			plugin>
		plugins>
	build>



	<profiles>
		<profile>
			<id>devid>
			<activation>
				<activeByDefault>trueactiveByDefault>
			activation>

			<properties>
				<profilesActive>devprofilesActive>
			properties>

		profile>
		<profile>
			<id>testid>
			<properties>
				<profilesActive>testprofilesActive>
			properties>
		profile>
		<profile>
			<id>prodid>
			<properties>
				<profilesActive>prodprofilesActive>
			properties>
			<build>
				<filters>
					<filter>/Users/xxx/Desktop/prod.propertiesfilter>
				filters>
			build>

		profile>
	profiles>

如果使用的是 application-prod.yml 文件; 里面的占位符会被prod.properties替换掉 占位符用 两个@@ 例如:@jdbc.name@

0 人点赞