Spring命名空间注入

p命名空间注入

  1. 需要有set方法
  2. 需要添加约束
xmlns:p="http://www.springframework.org/schema/p"
  1. xml配置文件
<?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:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
        
        <bean id="people" class="cn.lee.bean.People" p:name="鲁迅" p:age="65">        	
        </bean> 
</beans>

c命名空间注入

  1. 需要有构造方法
  2. 需要添加约束
xmlns:c="http://www.springframework.org/schema/c"
  1. xml配置文件
<?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:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
        
        <bean id="people" class="cn.lee.bean.People" c:name="鲁迅" c:age="65"></bean> 
</beans>

猜你喜欢

转载自blog.csdn.net/qq_40392686/article/details/82924857