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