Testutil.java
1 PackageCom.lh.util;2 3 Importjava.util.Properties;4 5 Public classTestutil {6 PrivateProperties prop;7 8 PublicProperties Getprop () {9 returnprop;Ten } One A @Override - PublicString toString () { - return"Testutil [prop=" + prop + "]"; the } - - Public voidSetProp (Properties prop) { - This. Prop =prop; + } - +}
Spring configuration file
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 Xmlns:context= "Http://www.springframework.org/schema/context"5 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd6 Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-4.1.xsd ">7 8 <BeanID= "Testutil"class= "Com.lh.util.TestUtil">9 < Propertyname= "prop">Ten <Props> One <propKey= "Driver">Com.mysql.jdbc.Driver</prop> A <propKey= "url">Jdbc:mysql://localhost:3306/test</prop> - <propKey= "username">Root</prop> - <propKey= "Password">111</prop> the </Props> - </ Property> - </Bean> - </Beans>
Spring Series "09" uses <prop> tags to inject values into the Java persistence property set