check an environment variable for null and get a file in spring el -
in our prod environment supply confdir
parameter server.xml in tomcat .properties file, in dev , test environments use properties file in classpath.
like this
<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"/>
now want load these properties files using util:properties
tag, shown below, accessing them in @value
, check null , if null assign default value
<util:properties id="classpathprops" location="classpath:jdbc.properties" local-override="false" /> <util:properties id="confdirprops" location="{confdir:}/jdbc.properties" local-override="false" />
the problem util:properties
is throwing exception when don't supply confdir
property.
can please me solve issue. tried various spel expression
location="#{${confdir}?${confdir:}/jdbc.properties:''}"
to check whether confdir
null or not, trials end in vain.
you don't need spel; use normal property placeholder default value...
<util:properties id="foo" location="${foo:classpath:}props"/>
then, if run no foo property, get...
class path resource [props] cannot opened because not exist
if run -dfoo=bar/
, get...
class path resource [bar/props] cannot opened because not exist
if run -dfoo=file:/bar/
/bar/props (no such file or directory)
in ${foo:classpath:}props
, value after first colon replacement used if property foo
doesn't exist.
Comments
Post a Comment