Spring beans using parameter placeholders (JDBC configuration read example)
Beans.xml configuration file
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans . xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-con Text.xsd "> <Context:property-placeholder Location= "Db.properties"/> <!--How to configure a placeholder - <BeanID= "Dbutil"class= "Com.my.util.DBUtil"> < Propertyname= "DriverName"value= "${drivername}"/> < Propertyname= "url"value= "${url}"/> < Propertyname= "username"value= "${username}" /> < Propertyname= "pwd"value= "${pwd}"/> </Bean> <!--register Propertyplaceholderconfigurer object, <bean id= "Propertyplaceholderconfigurer" class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer "> <property name=" Locations "> < ;list> <value>db.properties</value> </list> </property> </bean> - </Beans>
Db.properties configuration file
Drivername=com.mysql.jdbc.driverurl=jdbc:mysql://127.0.0.1:3306/jg29username=rootpwd=root
(# Reduce coupling, in line with the opening and closing principle of "to expand Open, to modify the source closed")
Java EE notes (11)