Followers

Wednesday, September 25, 2013

How to read properties in applicationcontext.xml loading by Spring PropertyPlaceholderConfigurer & Spring util

If we are using PropertyPlaceholderConfigurer to load the properties then we can read the property using $
Example:-
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:config.properties"></property>
</bean>

<!-- Definition for DataSource Start-->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc_driverClassName}" />
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_username}" />
<property name="password" value="${jdbc_password}" />
</bean>

If we are using util schema to load the properties then we can read the property using #{beanID.propertyName} like #{config.jdbc_driverClassName}

<util:properties id="config" location="classpath:config.properties"></util:properties>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="#{config.jdbc_driverClassName}"/>
<property name="url" value="#{config.jdbc_url}"/>
<property name="username" value="#{config.jdbc_username}"/>
<property name="password" value="#{config.jdbc_password}"/>
</bean>

If anyone has any better solution welcome..
Posted by Mohit Choudhary(Technical Lead) at 6:47 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Home
Subscribe to: Post Comments (Atom)

Spring Framework

All the issue faced in Spring 3 web application development

About Me

My photo
Mohit Choudhary(Technical Lead)
View my complete profile

Blog Archive

  • ▼  2013 (1)
    • ▼  September (1)
      • How to read properties in applicationcontext.xml l...
Simple theme. Theme images by Jason Morrow. Powered by Blogger.