【问题标题】:Java Spring - Import resource based on Placeholder ExpressionJava Spring - 基于占位符表达式导入资源
【发布时间】:2014-01-22 09:08:58
【问题描述】:

在春天,我想做以下事情:

<import resource="${resourceFile}" />

但是,'resourceFile' 不会被导入评估。

我需要它工作的原因是我定义了两个不同的资源文件: 资源-serviceA.xml 资源-serviceB.xml

上述每个文件都定义了不同的 bean 集。运行 ServiceA 时,我不需要 ServiceB 所需的 bean,因此我不想创建它们。

关于如何实现这一点的任何指示?

我们使用的是 Spring 3.0。

【问题讨论】:

  • 您在什么时候决定您的应用程序是在运行服务 A 还是 B?我很好奇为什么您可以更改 .properties 文件而不是类似的 XML 文件。

标签: java spring


【解决方案1】:

Spring 3.0 不能评估 import 标签内的属性,评估这些是 Spring 3.1 的新特性之一(2011 年) 见Spring 3.1 M1: Unified Property Management

所以基本上你应该使用实际版本的 Spring。 Spring 3.1+还引入了bean profiles,所以可以在不同的profile中定义ServiceA和ServiceB。

如果您对 Spring 3.0 的用户如何解决此问题感兴趣,您可以查看 Import Spring config file based on property in .properties file 但请记住 Spring 3.0 现在已经 3 年了,对 3yo 的基本引导配置进行更改是可疑的项目,考虑切换到 Spring 4.0+。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 2016-07-05
    • 2017-01-26
    • 2013-01-24
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    相关资源
    最近更新 更多