I have been working on an application that loads spring security beans from a separate xml file based upon the settings in a properties file. However, it looks like spring expressions fail to work in the import tag, which surprised me. Here is a summarized look at my configuration:
The idea is to build using either dev.properties or prod.properties, and automatically import security beans customized to those environments. Unfortunately, when I try this I get the following:Code:<util:properties id="appProperties" location="classpath:/#{systemProperties['environment'] ?: 'dev'}.properties" /> <import resource="#{ appProperties['security.context'] }"/>
Caused by: org.springframework.beans.factory.xml.XmlBeanDefin itionStoreException: Line 1 in XML document from URL [file:/target/test-classes/#{ appProperties['security.context'] }] is invalid; nested exception is org.xml.sax.SAXParseException: Content is not allowed in prolog.
It looks to me like the expression isn't being evaluated. If I manually replace #{} with the value in the properties file, it works perfectly.
Did I do something wrong, or is this a bug? If not, why can't we evaluate an expression in that location?


Reply With Quote