我正在 OSGi-inf/blueprint/下的 context.xml 中加载 cfg 文件 在我的 context.xml 文件中:
...
<cm:property-placeholder
persistent-id="com.lolo.${project.version}"
update-strategy="reload">
<cm:default-properties>
<cm:property name="testValue" value="" />
</cm:default-properties>
</cm:property-placeholder>
<ext:property-placeholder placeholder-prefix="$sys["
placeholder-suffix="]" />
在我的 cfg 文件中我得到:
testValue=$sys[jdbcUrl]
这会正确加载jdbc env属性并将其注入(inject)context.xml中(testValue稍后将注入(inject)到Java类中,这是非常有用的)
我的问题是每当我删除此代码时
`<ext:property-placeholder placeholder-prefix="$sys["
placeholder-suffix="]" />`
我替换
testValue=$sys[jdbcUrl]
with
testValue=${project.version}
现在我没有得到与以前相同的行为,project.version 未加载,testValue 保持为空
我应该怎么做才能正确注入(inject) ${projetc.version}
?
最佳答案
ext:property-placeholder 定义意味着您可以使用 $sys[] 引用任何系统属性。
因此,要访问属性project.version,请尝试:$sys[project.version]。 当然,要实现此功能,您必须提供系统属性,例如在 Surefire 配置中。
关于java - 如何替换 blueprint/context.xml 中加载的 cfg 文件中的文本值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58217033/