p命名空间
1. 需要引入命名空间p 并不真实存在 是在spring内部中实现的
xmlns:p="http://www.springframework.org/schema/p"
2. 如果是引用注入需要加-ref后缀 p和c命名空间 并不适用于集合参数
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" <!-- 1 -->
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="john-classic" class="com.example.Person">
<property name="name" value="John Doe"/>
<property name="spouse" ref="jane"/>
</bean>
<bean name="john-modern"
class="com.example.Person"
p:name="John Doe" <!-- 2 -->
p:spouse-ref="jane"/> <!-- 3 -->
<bean name="jane" class="com.example.Person">
<property name="name" value="Jane Doe"/>
</bean>
</beans>
c命名空间
1. 需要引入命名空间c 并不真实存在 是在spring内部中实现的
xmlns:c="http://www.springframework.org/schema/c"
2.可以使用c:参数名 或c:_参数index 两种方式
因为xml命名空间中属性名不能以数字开头 所以加了_
3. 如果是引用注入需要加-ref后缀
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c" <!-- 1 -->
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="bar" class="x.y.Bar"/>
<bean id="baz" class="x.y.Baz"/>
<-- 'traditional' declaration -->
<bean id="foo" class="x.y.Foo">
<constructor-arg ref="bar"/>
<constructor-arg ref="baz"/>
<constructor-arg value="foo@bar.com"/>
</bean>
<-- 'c-namespace' declaration --> <!-- 2 -->
<bean id="foo" class="x.y.Foo" c:bar-ref="bar" c:baz-ref="baz" c:email="foo@bar.com">
<-- 'c-namespace' index declaration --> <!-- 3 -->
<bean id="foo2" class="x.y.Foo" c:_0-ref="bar" c:_1-ref="baz">
</beans>