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>

  • 相关阅读:
    CSP 2020 提高组第一轮
    初赛胡扯
    Sublime安装SublimeServer插件开启本地服务器
    Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in XXX ode_modules@babelhelper-compilation-targetspackage.json
    Vue解决less-loader报错 TypeError: this.getOptions is not a function
    Vue-cli项目关闭eslint检查
    Typora添加主题
    Oracle存储过程中EXECUTE IMMEDIATE 执行结果是空时怎么继续执行
    存储过程--异常捕获
    git和github的基本使用(2)
  • 原文地址:https://www.cnblogs.com/aashui/p/8735195.html
Copyright © 2011-2022 走看看