pom变量:
<profiles> <profile> <!-- 本地环境 --> <id>dev</id> <properties> <profiles.env>dev</profiles.env> <jdbc-url>jdbc:mysql://127.0.0.1:3306/melab?allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai</jdbc-url> <lcn-log-url>jdbc:mysql://127.0.0.1:3306/tx-manager?allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai</lcn-log-url> <jdbc-user>root</jdbc-user> <jdbc-password>123456</jdbc-password> </properties> </profile> </profiles>
yml获取pom变量:
添加依赖:
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml --> <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> <version>1.25</version> </dependency>
获取变量:
url: @jdbc-url@ lcn-log-url: @jdbc-url@ username: @jdbc-user@ password: @jdbc-password@
properties获取pom变量:
build设置:
<build> <!--properties解析pom--> <pluginManagement> <plugins> <plugin> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>utf-8</encoding> <useDefaultDelimiters>true</useDefaultDelimiters> </configuration> </plugin> </plugins> </pluginManagement> </build> 获取变量: spring.datasource.url=${jdbc-url} spring.datasource.username=${jdbc-user} spring.datasource.password=${jdbc-password}