Spring (3.2.3)-Beans (12): Property placeholder

Source: Internet
Author: User

You can use the property placeholder to set some of the metadata in a Spring configuration file in a property file so that similar configurations (such as JDBC parameter configuration) are placed in a specific property file, and if you only need to modify this configuration, you do not need to modify the spring configuration file to modify the properties file. The following is an example of a property placeholder.

Spring configuration:

<!--The configuration values are materialized into a property file, and the key name of the property file is used as a placeholder -<Context:property-placeholder Location= "Classpath:jdbc.properties"/><BeanID= "DataSource"class= "Org.apache.commons.dbcp.BasicDataSource"Destroy-method= "Close">    < Propertyname= "Driverclassname"value= "${jdbc.driverclassname}" />    < Propertyname= "url"value= "${jdbc.url}" />    < Propertyname= "username"value= "${jdbc.username}" />    < Propertyname= "Password"value= "${jdbc.password}" /></Bean>

Properties configuration file:

Jdbc.driverclassname=com.mysql.jdbc.driverjdbc.url=jdbc:mysql://localhost:3306/dream?characterencoding=utf-8 &autoreconnect=truejdbc.username=rootjdbc.password=root

In the above configuration file, the configuration of Driverclassname, URLs and other information, not directly set the property values of these properties, but set the ${jdbc.driverclassname} and ${jdbc.url} property values, which indicates that Spring The container searches for the value corresponding to these keys from the specified property file and sets these value values for the Bean's property values.

Spring (3.2.3)-Beans (12): Property placeholder

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.