学习spring(二)

使用set方法注入属性

和使用构造参数注入的唯一区别,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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <bean id="Di1" class="cn.bdqn.pojo.User">
        <property name="username" value="admin"></property>
    </bean>
</beans>

测试结果:

注入成功!

 

posted @ 2017-12-01 16:40  酒肉穿肠过I  阅读(97)  评论(0编辑  收藏  举报