记录一些spring配置文件的格式,以下并不是完整的xml配置文件。
1、mybatis mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.common.dal.dao.legacy.ItemDOMapper">
<resultMap id="BaseResultMap" type="com.common.dal.entity.legacy.ItemDO">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="res_id" jdbcType="INTEGER" property="resId"/>
<result column="utime" jdbcType="TIMESTAMP" property="utime"/>
</resultMap>
<sql id="Base_Column_List">
id,res_id, utime
</sql>
</mapper>
2、spring-mybatis配置文件
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="${jdbc.url}"
p:user="${jdbc.user}"
p:password="${jdbc.password}"
p:maxPoolSize="10"
p:minPoolSize="2"
p:initialPoolSize="2"
p:acquireIncrement="1"
p:maxIdleTime="60"
p:checkoutTimeout="30000"/>
<!-- 配置sqlSessionFactory工厂 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:META-INF/mybatis/mapper/**/*.xml"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value>
helperDialect=mysql
reasonable=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
<property name="rollbackOnCommitFailure" value="true"/>
</bean>
<!-- 采用spring与mybatis整合的第二种方法 -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.common.dal.dao"/>
</bean>
</beans>
3、spring-context配置文件
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<aop:aspectj-autoproxy/>
<context:component-scan base-package="com.xcy.admin" use-default-filters="false">
<!-- 扫描符合@Controller @Service @Repository的类 -->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
<context:include-filter type="annotation" expression="org.springframework.context.annotation.Configuration"/>
</context:component-scan>
<mvc:annotation-driven/>
<!-- 配置中心数据 -->
<bean class="com.xcy.client.configPropertyConfigurer">
<property name="locations">
<list>
<value>classpath:config/xcy.properties</value>
</list>
</property>
</bean>
<import resource="spring-web-context.xml"/>
<import resource="classpath:META-INF/spring/spring-common-dal-context.xml"/>
<import resource="classpath:META-INF/spring/spring-core-context.xml"/>
<import resource="classpath:META-INF/spring/spring-mq.xml"/>
<import resource="classpath:META-INF/spring/spring-redis.xml"/>
</beans>