Load properties file in spring application context 2013

Go down

Load properties file in spring application context 2013

Post by Admin on Sun Sep 15, 2013 4:04 am

2013 2013 2013 <div dir="ltr" style="text-align: left;" trbidi="on">There are two ways to load a property file in spring configuration xml file.<br /><br />1) Using org.springframework.beans.factory.config.PropertyPlaceholderConfigurer class<br />2) Using tag &lt;context:property-placeholder/&gt;<br /><br />1) Using org.springframework.beans.factory.config.PropertyPlaceholderConfigurer class<br /><br />spring-config.xml <pre style="font-family:arial;font-size:12px;border:1px solid #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; <br /> &lt;beans xmlns="http://www.springframework.org/schema/beans" <br /> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br /> xmlns:context="http://www.springframework.org/schema/context" <br /> xmlns:p="http://www.springframework.org/schema/p" <br /> xsi:schemaLocation=" <br /> http://www.springframework.org/schema/beans <br /> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <br /> http://www.springframework.org/schema/context <br /> http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; <br /> &lt;bean id="props" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; <br /> &lt;property name="locations" value="classpath:com/eclipse/e3.properties" /&gt; <br /> &lt;/bean&gt; <br /> &lt;bean id="xyz" class="CLASS_NAME"&gt; <br /> &lt;property name="domainName" value="${domainName}"/&gt; <br /> &lt;property name="instanceName" value="${instanceName}"/&gt; <br /> &lt;/bean&gt; <br /> &lt;/beans&gt; <br /></code></pre>e3.properties <pre style="font-family:arial;font-size:12px;border:1px solid #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> domainName=rulesdomain <br /> instanceName=DOC_DEV <br /></code></pre>2) Using tag &lt;context:property-placeholder/&gt; <pre style="font-family:arial;font-size:12px;border:1px solid #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; <br /> &lt;beans xmlns="http://www.springframework.org/schema/beans" <br /> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br /> xmlns:context="http://www.springframework.org/schema/context" <br /> xmlns:p="http://www.springframework.org/schema/p" <br /> xsi:schemaLocation=" <br /> http://www.springframework.org/schema/beans <br /> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <br /> http://www.springframework.org/schema/context <br /> http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; <br /> &lt;context:property-placeholder location="classpath:com/eclipse/e3.properties" /&gt; <br /> &lt;bean id="xyz" class="CLASS_NAME"&gt; <br /> &lt;property name="domainName" value="${domainName}"/&gt; <br /> &lt;property name="instanceName" value="${instanceName}"/&gt; <br /> &lt;/bean&gt; <br /> &lt;/beans&gt; <br /></code></pre>At runtime, ${domainName} value will be replaced with the value from e3.properties file.</div><br> 2013 2013 2013 <br><div dir="ltr" style="text-align: left;" trbidi="on">There are two ways to load a property file in spring configuration xml file.<br /><br />1) Using org.springframework.beans.factory.config.PropertyPlaceholderConfigurer class<br />2) Using tag &lt;context:property-placeholder/&gt;<br /><br />1) Using org.springframework.beans.factory.config.PropertyPlaceholderConfigurer class<br /><br />spring-config.xml <pre style="font-family:arial;font-size:12px;border:1px solid #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; <br /> &lt;beans xmlns="http://www.springframework.org/schema/beans" <br /> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br /> xmlns:context="http://www.springframework.org/schema/context" <br /> xmlns:p="http://www.springframework.org/schema/p" <br /> xsi:schemaLocation=" <br /> http://www.springframework.org/schema/beans <br /> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <br /> http://www.springframework.org/schema/context <br /> http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; <br /> &lt;bean id="props" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; <br /> &lt;property name="locations" value="classpath:com/eclipse/e3.properties" /&gt; <br /> &lt;/bean&gt; <br /> &lt;bean id="xyz" class="CLASS_NAME"&gt; <br /> &lt;property name="domainName" value="${domainName}"/&gt; <br /> &lt;property name="instanceName" value="${instanceName}"/&gt; <br /> &lt;/bean&gt; <br /> &lt;/beans&gt; <br /></code></pre>e3.properties <pre style="font-family:arial;font-size:12px;border:1px solid #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> domainName=rulesdomain <br /> instanceName=DOC_DEV <br /></code></pre>2) Using tag &lt;context:property-placeholder/&gt; <pre style="font-family:arial;font-size:12px;border:1px solid #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> &lt;?xml version="1.0" encoding="UTF-8"?&gt; <br /> &lt;beans xmlns="http://www.springframework.org/schema/beans" <br /> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br /> xmlns:context="http://www.springframework.org/schema/context" <br /> xmlns:p="http://www.springframework.org/schema/p" <br /> xsi:schemaLocation=" <br /> http://www.springframework.org/schema/beans <br /> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <br /> http://www.springframework.org/schema/context <br /> http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; <br /> &lt;context:property-placeholder location="classpath:com/eclipse/e3.properties" /&gt; <br /> &lt;bean id="xyz" class="CLASS_NAME"&gt; <br /> &lt;property name="domainName" value="${domainName}"/&gt; <br /> &lt;property name="instanceName" value="${instanceName}"/&gt; <br /> &lt;/bean&gt; <br /> &lt;/beans&gt; <br /></code></pre>At runtime, ${domainName} value will be replaced with the value from e3.properties file.</div><br>2013 2013 2013 <br> <a href="http://www.matrixar.com/" title="Matrix ">المصفوفة : أجمل الخلفيات والصور</a>

Admin
Admin

Posts : 64122
Join date : 2013-02-22

View user profile http://prowebsites1.forumaroc.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum