bean的引用标签

<import resource="Spring-dao.xml"></import>

就是将spring-dao.xml引用了,在这个类中,随便使用spring-dao.xml中定义的bean,如下的ref就是spring-dao.xml中的

如果不写import标签,ref会爆红

虽然Spring-dao.xml中声明了sqlSessionFactory这个bean(就是把这个类放进了ioc容器),但是在其他的xml文件中并不能直接使用这个bean,因为xml文件是用来声明bean的,不能从ioc容器中直接获取bean,只能引用该文件自己声明好的bean或者import的xml文件中的bean

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">
    <import resource="Spring-dao.xml"></import>
<!--    <bean id="Accountmapper" class="com.atguigu.rj1192.zyk.dao.AccoountDaoImpl">-->
<!--        <property name="sqlSession" ref="sqlsession"></property>-->
<!--    </bean>-->
    <bean id="AccoountDaoImpl2" class="com.atguigu.rj1192.zyk.dao.AccoountDaoImpl2">
        <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
    </bean>
</beans>

 ref想从ioc容器中拿实例,是拿不到的,ref只能使用本xml文件中定义的bean,或者import的xml文件中的bean

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值