<?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-4.2.xsd">

	<!-- 解析配置文件 -->
	<!-- system-properties-mode 如果不配置,读取的就不是数据库的用户名了,将会读取电脑本机的用户名 -->
	<context:property-placeholder location="classpath:db.properties" system-properties-mode="FALLBACK"/>
	
	
		
	<!-- 声明数据源 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
		<property name="driverClassName" value="${driver}"></property>
		<property name="url" value="${url}"></property>
		<property name="username" value="${user}"></property>
		<property name="password" value="${password}"></property>
		<property name="maxActive" value="${maxActive}"></property>
		<property name="initialSize" value="${initialSize}"></property>
		<property name="maxWait" value="${maxWait}"></property>
		<property name="minIdle" value="${minIdle}"></property>
		<property name="filters" value="${filters}"></property>
	</bean>
	
	
	
	
	
	
	<!-- 创建mybatis的 configuration对象-->
	<bean id="configuration" class="org.apache.ibatis.session.Configuration">
	<!--日志的输出形式 -->
		<property name="logImpl" value="org.apache.ibatis.logging.stdout.StdOutImpl"></property>
	</bean>
	
	
	
	
	
	<!-- 创建sqlSessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 注入数据源 -->
		<property name="dataSource" ref="dataSource"></property>
		
		<!--  以前是加载本地文件SqlMapConfig.xml文件,用的是configlocation-->
		<!--  现在没有SqlMapConfig.xml这个文件了,所以只能自己声明,用的是configuration-->
		<!-- 注入配置类 -->
		<property name="configuration" ref="configuration"></property>
		
		<!-- 扫描mapper.xml -->
		<property name="mapperLocations">
			<array>
				<value>classpath:mapper/*Mapper.xml</value>
			</array>
		</property>
		<!-- 别名包扫描 -->
		<property name="typeAliasesPackage" value="com.lishan.domain" />
		<!-- 配置分页插件 -->
		<property name="plugins">
			<array>
				<bean class="com.github.pagehelper.PageInterceptor"></bean>
			</array>
		</property>
	</bean>
	
	
	
	
	
	
	<!-- 配置mapper接口的扫描 --><!--因为mapper接口和mapper.xml文件分开放了所以这里扫描接口,上面是扫描xml文件  -->
	<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- 如果要扫描多个包。用逗号隔开(第一种方法) -->
		<property name="basePackage" value="com.lishan.mapper"></property>
		<!--  如果要扫描多个包。(第二种方法)-->
		<!-- <property name="basePackage">
			<value>
				com.sxt.mapper
				com.bjsxt.mapper
			</value>
		</property> -->
		
		<!-- 注入sqlSessionFactory -->
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
		
	</bean>

</beans>

 


版权声明:本文为liulianzi_147原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/liulianzi_147/article/details/105571903