SSM整合之spring.xml

最近在使用SSM整合一个通用的后台管理系统,记录一下自己的整合过程,方便以后查阅,今天我们来说一下spring.xml,该配置文件通常放置在WebRoot/WEB-INF文件夹下面,该配置文件会随着自己的整合不断修改。配置文件如下:

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
   <!--扫描注解 (自动注入)-->
   <context:component-scan base-package="com.cesoft"></context:component-scan>
   <!--引入属性文件 -->  
    <context:property-placeholder location="classpath:jdbc.properties" />  
    <!--数据源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/mybatis"></property>
        <property name="user" value="root"></property>
        <property name="password" value="root"></property>
    </bean>
<!--     sqlSessionFactory,引入数据源,配置映射文件位置 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="mapperLocations" value="classpath:com/cesoft/mapper/*Mapper.xml"></property>
    </bean>
<!--     mapperScannerConfigurer,生成代理,名称为接口名第一个字母小写 ,引入sqlsessionfactory-->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--     指定基础包的位置 -->
        <property name="basePackage" value="com.cesoft.mapper"></property>
        <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
    </bean>
<!--     声明式事务,引入数据源 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
</beans>

猜你喜欢

转载自blog.csdn.net/u011872945/article/details/80726354