使用p標籤能夠簡化xml文件配置mysql
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd"> <bean id="car" class="com.test.spring.beans.Car"> <property name="name" value="audi"></property> <property name="address" value="shanghai"></property> <!-- <property name="price" value="200"></property> --> </bean> <bean id="car2" class="com.test.spring.beans.Car"> <property name="name" value="ford"></property> <property name="address" value="chengdu"></property> <!-- <property name="price" value="15"></property> --> </bean> <!-- 配置properties屬性值 --> <bean id="dataSource" class="com.test.spring.beans.DataSource"> <property name="properties"> <props> <prop key="username">root</prop> <prop key="password">123456</prop> <prop key="url">jdbc:mysql://192.168.2.11/test</prop> <prop key="driverClass">com.mysql.jdbc.Driver</prop> </props> </property> </bean> <!-- 配置獨立的集合bean,以供其餘的bean引用,須要導入util 命名空間 --> <util:list id="cars"> <ref bean="car"/> <ref bean="car2"/> </util:list> <!-- 引用bean --> <bean id="person2" class="com.test.spring.beans.Person2" p:name="zhangsan" p:age="30" p:cars-ref="cars"> <!-- <property name="name" value="zhangsan"></property> <property name="age" value="30"></property> <property name="cars" ref="cars"></property> --> </bean> </beans>