Spring框架配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	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
	http://www.springframework.org/schema/context
 	http://www.springframework.org/schema/context/spring-context.xsd
 	">
 
 	<!-- 
		jdbc.properties(需要读取) -> 配置连接池(dataSource) -> SqlSessionFactory -> Mapper对象 -> Service层
		由于要使用注解,所以service层需要扫描
	 -->
 	
 	<!--读取jdbc.properties文件   -->
 	<context:property-placeholder location="classpath:jdbc.properties"/>
 	
 	 <!-- 
	 	在Spring中配置连接池:要使用到BasicDataSource这个类
	 		连接池中至少要有四大金刚:驱动,路径,用户名,密码
	 		记住:连接池用完需要关闭(节约资源)
	 			destroy-method="close"
	  -->
 	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
 		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
 	</bean>
 	
 	<!-- 
		配置SqlSessionFactory对象
			咱们今天导入了一个包: mybatis-spring.jar -> 它是用来做集成的
			它为咱们准备了一个类(SqlSessionFactoryBean),这个类配置成bean,咱们的SqlSessionFactory就可以出来了
				想要它起作用的话,需要给它加一些属性: 连接池,取别名(扫描包),找到映射文件
	 -->
	 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
	 	<!--配置连接池  -->
	 	<property name="dataSource" ref="dataSource" />
	 	<!-- 找映射文件 -->
	 	<property name="mapperLocations" value="classpath:cn/itsource/mapper/*.xml" />
	 </bean>
	 
	  <!--  
	 	Mapper(映射)Scanner(扫描)Configurer(配置)
	 	创建Mapper对象出来,创建出来后以后就可以直接用
	 		这个功能依然是mybatis-spring.jar包中完成
	 		MapperFactoryBean : 只可以一个Mapper一个Mapper的配置
	 		MapperScannerConfigurer :扫描(一扫描,所有mapper都生成了)
	 -->
	 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
	 	<property name="basePackage" value="cn.itsource.mapper"/>
	 </bean>
	 
	 <!--扫描service-->
	 <context:component-scan base-package="cn.itsource.service"></context:component-scan>
</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值