p命名空间
- 实体类中必须有set方法;
- 实体类中必须有无参构造器(默认存在);
- 导入p命名空间注入方式依赖。
<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.0.xsd">
<bean id="demo1" class="com.Demo1" p:dog="小黄"/>
<bean id="helloWorld" class="com.HelloWorld" p:a="a" p:b="b" p:demo1-ref="demo1"/>
</beans>
c命名空间
- 实体类中必须存在有参构造器;
- 导入c命名空间注入方式依赖。
<?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"
xmlns:c="http://www.springframework.org/schema/c"
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.0.xsd">
<bean id="demo1" class="com.Demo1" p:dog="小黄"/>
<bean id="helloWorld" class="com.HelloWorld" c:a="a" c:b="b" c:demo1-ref="demo1"/>
</beans>