Spring的p命名空间
p命名空间是对IoC/DI的一个简化,使用p命名空间可以更加方便、简单的完成bean的配置以及bean之间的依赖注入。
使用p命名空间我们需要在配置文件中引入。
<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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> </beans>
xmlns:p="http://www.springframework.org/schema/p"
然后就可以使用p命名空间了。
<bean id="student" class="com.exambner.ioc.Student" p:id="1" p:name="小明" p:age="18"></bean>
它就相当于我们之前的property写法。
<bean id="student" class="com.exambner.ioc.Student"> <property name="id" value="1"></property> <property name="name" value="小明"></property> <property name="age" value="18"></property> </bean>

浙公网安备 33010602011771号