如何通过Maven profile实现针对不同环境的复杂配置管理?

2026-04-19 18:173阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计530个文字,预计阅读时间需要3分钟。

如何通过Maven profile实现针对不同环境的复杂配置管理?

环境:eclipse + spring + mvc + maven

1.直接查看图,将数据库配置文件单独拿出放在resources_env目录下。

2.三个不同环境参数不同。

3.在pom文件中添加配置:profiles profile !-- 开发环境 -- id dev/id p

环境:eclipse + spring mvc + maven

1、直接看图,把数据库的配置单独拿出来放在了resources_env目录下,三个不同环境参数不同,

2,在pom文件中添加配置

<profiles> <profile> <!-- 开发环境 --> <id>dev</id> <properties> <env>dev</env> </properties> <activation> <!-- 默认激活该profile节点--> <activeByDefault>true</activeByDefault> </activation> <build> <resources> <resource> <directory>src/main/resources_env/dev</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <!-- 测试环境 --> <id>qa</id> <properties> <env>qa</env> </properties> <build> <resources> <resource> <directory>src/main/resources_env/qa</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <!-- 生产环境 --> <id>online</id> <properties> <env>online</env> </properties> <build> <resources> <resource> <directory>src/main/resources_env/online</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> </profiles>

说明:这个resources里面的路径对应上面文件路径,resources里面所有的配置加上各自环境的配置,

在引用jdbc.pro的地方如下:在datasource.xml中,

还有 新增的 evn那个包下面的所有文件都需要设置为资源文件,这个不必说 直接看图

3,maven设置要使用的环境:

项目右键-->maven-->Select Maven profiles ,选择一个环境,修改最好清理一下项目才生效,我之前没清理,发现没起作用。

如何通过Maven profile实现针对不同环境的复杂配置管理?

4、然后运行项目就是你选择的环境了,或者直接导出war包,

其他的多环境配置同。

到此这篇关于maven profile实现多环境配置的示例的文章就介绍到这了,更多相关maven profile多环境配置内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

标签:示例

本文共计530个文字,预计阅读时间需要3分钟。

如何通过Maven profile实现针对不同环境的复杂配置管理?

环境:eclipse + spring + mvc + maven

1.直接查看图,将数据库配置文件单独拿出放在resources_env目录下。

2.三个不同环境参数不同。

3.在pom文件中添加配置:profiles profile !-- 开发环境 -- id dev/id p

环境:eclipse + spring mvc + maven

1、直接看图,把数据库的配置单独拿出来放在了resources_env目录下,三个不同环境参数不同,

2,在pom文件中添加配置

<profiles> <profile> <!-- 开发环境 --> <id>dev</id> <properties> <env>dev</env> </properties> <activation> <!-- 默认激活该profile节点--> <activeByDefault>true</activeByDefault> </activation> <build> <resources> <resource> <directory>src/main/resources_env/dev</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <!-- 测试环境 --> <id>qa</id> <properties> <env>qa</env> </properties> <build> <resources> <resource> <directory>src/main/resources_env/qa</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <!-- 生产环境 --> <id>online</id> <properties> <env>online</env> </properties> <build> <resources> <resource> <directory>src/main/resources_env/online</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> </profiles>

说明:这个resources里面的路径对应上面文件路径,resources里面所有的配置加上各自环境的配置,

在引用jdbc.pro的地方如下:在datasource.xml中,

还有 新增的 evn那个包下面的所有文件都需要设置为资源文件,这个不必说 直接看图

3,maven设置要使用的环境:

项目右键-->maven-->Select Maven profiles ,选择一个环境,修改最好清理一下项目才生效,我之前没清理,发现没起作用。

如何通过Maven profile实现针对不同环境的复杂配置管理?

4、然后运行项目就是你选择的环境了,或者直接导出war包,

其他的多环境配置同。

到此这篇关于maven profile实现多环境配置的示例的文章就介绍到这了,更多相关maven profile多环境配置内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

标签:示例