【问题标题】:Maven: Managing Spring configurationsMaven:管理 Spring 配置
【发布时间】:2013-06-17 22:48:32
【问题描述】:

我有几组 Spring 配置(用于 bean 初始化的 XML 文件和属性文件),用于不同类型的服务/服务器。我还使用 maven 来管理依赖项和构建(与 eclipse 交替)。

我的意图是有一个标志,我可以将其传递给 maven 以使用选定的配置文件构建项目。

例子:

mvn package production

将 conf/production 文件放在 WEB-INF/classes 中

【问题讨论】:

  • 使用 Maven 配置文件。在命令行用-P切换它们或使用各种激活方法。
  • Maven Profile Best Practices 说:“使用配置文件来适应构建时上下文,而不是运行时上下文,而不是(除了极少数例外)来生成工件的替代版本”。就我而言,我想更改运行时上下文。
  • 你知道 Spring Profiles 吗?使用相同的构建,您可以拥有不同的配置,然后 maven 会为您的环境加载适当的配置。见static.springsource.org/spring/docs/3.2.x/…

标签: spring maven configuration


【解决方案1】:

我已经通过使用@gerardribas 建议的 Spring 配置文件的方法解决了这个问题。 我查看了Jhipster implementation 并按照这种方式进行操作。如果有人遵循相同的路径,请注意您需要将 servlet 版本升级到 3.x。

【讨论】:

    最近更新 更多