Util:properties and Context:property-placeholder in spring configuration files

Source: Internet
Author: User
Tags connection pooling

Both the util:properties and Context:property-placeholder tags can be used to get the contents of the external configuration file
1, Util:properties
It is used in the way of declaring beans, creating a bean, using the Spel expression #{} to get the Bean's properties.

<Util:propertiesId="Config"location="Classpath:db.properties"/><!--Configure connection pooling--<BeanId="DS"class="Org.apache.commons.dbcp.BasicDataSource"Destroy-method="Close" ><PropertyName= "driverclassname" value= "#{ Config.driver} "/><property  Name= "url" value= "#{config.url}" /><property name= "username" value= "#{config.username}"/>< Span class= "Hljs-tag" ><property name=  "password" value= "#{ Config.password} "/></BEAN>     

It is important to note that this approach requires a header declaration in the Spring configuration file

xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"

2, Context:property-placeholder
It loads the configuration file into the spring context and then gets the value through ${}, which is commonly used on bean properties

<Context:property-placeholderlocation="Classpath:general.properties"/><!--Configure Druid Connection pool--<BeanId="DataSource"class="Com.alibaba.druid.pool.DruidDataSource" ><!--basic properties Driverclassname, URL, user, password--<PropertyName=  "driverclassname" value= "${ Jdbc.driverclassname} "/> <property name= "url" value= "${jdbc.url}"/> <property name=" username "value=  "${jdbc.username}"/> <property Span class= "Hljs-attribute" >name= "password" value= "${jdbc.password}"/></BEAN>   

Util:properties and Context:property-placeholder in spring configuration files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.