zoukankan      html  css  js  c++  java
  • applicationContext

    <?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:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/jdbc
    http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">
    <!-- spring 扫包 @Service -->
    <context:component-scan base-package="">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!-- 引入配置文件 -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <!--加载配置文件-->
    <context:property-placeholder location="classpath:resource/db.properties"/>
    </bean>

    <!--数据库连接池-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
    destroy-method="close">
    <property name="url" value="${jdbc.url}"/>
    <property name="name" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    <property name="driverClassName" value="${jdbc.driver}"/>
    <property name="maxActive" value="10"/>
    <property name="minIdle" value="5"/>
    </bean>


    <!-- mybatis 配置-->
    <!--spring和mybatis完美结合,不需要mybatis配置映射文件-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <!--mapperLocations:它表示我们的Mapper文件存放的位置,
    当我们的Mapper文件跟对应的Mapper接口处于同一位置的时候可以不用指定该属性的值。
    mapper文件就是xml文件-->
    <!--自动扫描mapper.xml文件-->
    <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    <property name="typeAliasesPackage" value="demo.bean"/>
    </bean>
    <!-- 扫包 -->
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!--这个扫描包必须写到准确的路径下-->
    <property name="basePackage" value="demo.dao"/>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>


    <!--配置扫描所有dao包,加载mapper对象-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="mapper"/>
    <!--<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />-->
    </bean>

    <!-- 事务配置 -->
    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" />
    </beans>

  • 相关阅读:
    NHibernate学习笔记manytoone/onetomany/manytomany(转)
    C#.NET使用NHibernate 1.0 XML映射使用中容易出错的地方全程记录(转)
    Interface定义及使用
    c#中的interface abstract 与 virtual(转)
    根据word模板生成word表格报表文档(C#)
    NHibernate中的manytomany关系示范(转)
    工作流平台简介(转自singbird(走夜路的人))
    【Hibernate总结系列】....hbm.xml配置
    CentOS 5.X(更新到6.3)最小化安装过程及网络配置+用yum安装Apache+PHP+MySQL
    CentOS 各版本下载地址和发布时间表(20190401更新)
  • 原文地址:https://www.cnblogs.com/aashui/p/8735195.html
Copyright © 2011-2022 走看看