0

I am trying to understand a configuration for spring written in XML.

...

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close" >
    <!-- These properties are replaced by Maven "resources" -->
    <property name="url" value="#{$.val('db.url')}" />
    <property name="driverClassName" value="#{$.val('db.driver')}" />
    <property name="username" value="#{$.val('db.user')}" />
    <property name="password" value="#{$.val('db.password')}" />
</bean>

The value field has variables defined as "#{$.val(...)}" . I understand that something like db.user are extracted from the project configuration file defined in base xml file. Can someone explain how does "#{$.val(...)}" work?

phoenix
  • 691
  • 1
  • 7
  • 24
  • http://stackoverflow.com/questions/5322632/spring-expression-language-spel-with-value-dollar-vs-hash-vs – isah Sep 30 '14 at 09:13
  • thanks @isah ... that helped! – phoenix Sep 30 '14 at 09:20
  • @isah that explains use of # and $ .. but if $ is for immediate evaluation and # is for deferred evaluation , how do they behave together. I mean if the definition is loaded the first time page is loaded, use of $ becomes redundant. And also the function of val(), is it used to parse from conf file or something else, since I thought conf parsing is supported by spring. – phoenix Sep 30 '14 at 09:27
  • Yes, I do not have an answer for usage of $.val(). I have never seen it, it looks like an implicit method. Normally you usually do either ${db.url} or #{db.url} for property files. – isah Sep 30 '14 at 09:29
  • Thanks. you really prodded me in the right direction! @isah – phoenix Sep 30 '14 at 09:51

1 Answers1

0

I just went through how 'exp'.'exp' works in el ; here '$'.val(). It means bean id being referenced. in this case, it means $ has been defined in another xml file.

<bean id="$" class="....Config">
    <constructor-arg index="0" value="/etc/...conf">
</bean>

So a deferred call is being made to "db.something" property defined in the conf file which is being referred to using the bean id "$" .

phoenix
  • 691
  • 1
  • 7
  • 24