p命名空間
其實就是Set注入 只不過p命名空間寫法更簡潔 p可以理解為 property標簽的首字母p
p命名空間依賴于set方法
依賴引入
使用前需要再配置文件頭文件中引入p命名空間的依賴: ** xmlns:p=“http://www.springframework.org/schema/p” **
用法
在bean標簽上用p:屬性名=“屬性值” 進行注入
<bean name="p-namespace" class="com.example.ExampleBean"p:email="someone@somewhere.com"/><!-- 等同于<bean name="classic" class="com.example.ExampleBean"><property name="email" value="someone@somewhere.com"/></bean>-->
c命名空間
其實就是構造器注入 只不過c命名空間寫法更簡潔 c可以理解為 constructor-arg 標簽的首字母c
c命名空間依賴于構造器
依賴引入
使用前需要再配置文件頭文件中引入c命名空間的依賴: ** xmlns:c=“http://www.springframework.org/schema/c” **
用法
在bean標簽上用c:構造器參數名="參數值"進行注入
<!-- c-namespace declaration with argument names --><bean id="beanOne" class="x.y.ThingOne" c:thingTwo-ref="beanTwo"c:thingThree-ref="beanThree" c:email="something@somewhere.com"/><!-- 等同于<bean id="beanTwo" class="x.y.ThingTwo"/><bean id="beanThree" class="x.y.ThingThree"/><bean id="beanOne" class="x.y.ThingOne"><constructor-arg name="thingTwo" ref="beanTwo"/><constructor-arg name="thingThree" ref="beanThree"/><constructor-arg name="email" value="something@somewhere.com"/></bean>-->