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