在我们的 prod 环境中,我们confDir
从 tomcat 中的 server.xml 提供参数以获取 .properties 文件,但在开发和测试环境中,我们使用类路径中的属性文件。
像这样
<context:property-placeholder location="${confDir:}/jdbc.properties, ${confDir:}/webservice.properties" order="1" ignore-resource-not-found="true" ignore-unresolvable="true"/>
<context:property-placeholder location="classpath:jdbc.properties, classpath:webservice.properties" order="2"/>
现在我想使用util:properties
标签加载这些属性文件,如下所示,用于访问它们@Value
并检查是否为空,如果为空则分配一个默认值
<util:properties id="classpathProps" location="classpath:jdbc.properties" local-override="false" />
<util:properties id="confDirProps" location="{confDir:}/jdbc.properties" local-override="false" />
问题util:properties
是当我们不提供confDir
属性时它会抛出异常。
有人可以帮我解决这个问题。我尝试了各种SpEL表达式,例如
location="#{${confDir}?${confDir:}/jdbc.properties:''}"
检查是否confDir
为空,但我的试验最终是徒劳的。