- application.xml文件种配置
–java
在这里插入代码片
<?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:rdb="http://www.dangdang.com/schema/ddframe/rdb"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.dangdang.com/schema/ddframe/rdb
http://www.dangdang.com/schema/ddframe/rdb/rdb.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:property-placeholder location="classpath*:*.properties" ignore-unresolvable="true"/>
<context:annotation-config />
<context:component-scan base-package="com.weijuju.iag.common"/>
<import resource="classpath*:iag-defaultRedis1.xml"/>
<import resource="classpath*:huaer-cmbRedis.xml"/>
<import resource="classpath*:core-dubbo.xml"/>
<import resource="classpath*:applicationContext-mq-producer.xml"/>
<!-- 数据库配置 -->
<context:annotation-config />
<tx:annotation-driven transaction-manager="iagTransactionManager" />
<bean id="iagDataSource" class="org.apache.commons.dbcp2.BasicDataSource"
destroy-method="close" primary="true">
<property name="driverClassName" value="${iag.db.driver}" />
<property name="url" value="${iag.db.url}" />
<property name="username" value="${iag.db.user}" />
<property name="password" value="${iag.db.password}" />
<property name="defaultAutoCommit" value="${iag.db.defaultAutoCommit}" />
<property name="maxTotal" value="${iag.db.maxTotal}" />
<property name="maxIdle" value="${iag.db.maxIdle}" />
<!-- 默认10秒 -->
<property name="maxWaitMillis" value="${iag.db.maxWaitMillis:10000}" />
<!-- 默认是8小时 -->
<property name="maxConnLifetimeMillis" value="${iag.db.maxConnLifetimeMillis:28800000}" />
</bean>
<!-- 定义事务管理器(声明式的事务) -->
<context:annotation-config />
<bean id="iagTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" primary="true">
<property name="dataSource" ref="iagDataSource" />
</bean>
<bean id="iagSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="iagDataSource" />
<property name="configLocation" value="classpath:iagMapperConfig.xml" />
<property name="mapperLocations">
<list>
<value>classpath*:sqlmap/**/*.xml</value>
</list>
</property>
</bean>
<bean id="iagMapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="iagSqlSessionFactory" />
<property name="basePackage" value="com.weijuju.iag.mapper" />
</bean>
<bean id="aliDataSource" class="org.apache.commons.dbcp2.BasicDataSource"
destroy-method="close" primary="true">
<property name="driverClassName" value="${aliyun.db.driver}" />
<property name="url" value="${aliyun.db.url}" />
<property name="username" value="${aliyun.db.user}" />
<property name="password" value="${aliyun.db.password}" />
<property name="defaultAutoCommit" value="${aliyun.db.defaultAutoCommit}" />
<property name="maxTotal" value="${aliyun.db.maxTotal}" />
<property name="maxIdle" value="${aliyun.db.maxIdle}" />
<!-- 默认10秒 -->
<property name="maxWaitMillis" value="${iag.db.maxWaitMillis:10000}" />
<!-- 默认是8小时 -->
<property name="maxConnLifetimeMillis" value="${iag.db.maxConnLifetimeMillis:28800000}" />
</bean>
<!-- 定义事务管理器(声明式的事务) -->
<context:annotation-config />
<bean id="aliTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" primary="true">
<property name="dataSource" ref="aliDataSource" />
</bean>
<bean id="aliSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="aliDataSource" />
<property name="configLocation" value="classpath:iagMapperConfig.xml" />
<property name="mapperLocations">
<list>
<value>classpath*:alisqlmap/**/*.xml</value>
</list>
</property>
</bean>
<bean id="aliMapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="aliSqlSessionFactory" />
<property name="basePackage" value="aliyun.mapper" />
</bean>
</beans>
填写数据库连接信息的对应的包路径
设置mapper.xml文件所在路径
设置mapper.java文件所在包路径