<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