zoukankan      html  css  js  c++  java
  • 简单配置applicationContext.xml

    <?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:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    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.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">


    <!-- 基于 mapper 接口通过动态代理产生实现类 -->
    <!-- <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    通过 value 值,扫描该包下的接口,从而产生实现类
    <property name="basePackage" value="com.ssm.dao"></property>
    该 bean 下会产生 dao 接口的实现类,并且该 bean 中会有 sqlSessionFactory 的依赖,配置之
    <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
    </bean> -->


    <!-- 3、sqlSessionFactory bean -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- sqlsessionfactory 依赖注入 datasource -->
    <property name="dataSource" ref="dataSource"></property>

    <!--
    管理 mybatis 的映射配置文件,该属性可管理多个配置文件
    name:表示该标签是管理 mybatis 的映射配置文件
    value:表示在类路径下需要管理的 mybatis 的映射配置文件
    -->
    <property name="mapperLocations" value="classpath:com/ssm/bean/*.xml"></property>

    <!--
    在包的前提下为数据 bean 取别名
    name:表示是基于包为数据 bean 取别名
    value:表示为哪个包下取别名
    -->
    <property name="typeAliasesPackage" value="com.ssm.bean"></property>
    </bean>

    <!-- 引入数据源配置文件 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!-- 5、dataSource bean -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <!-- 配置 c3p0 连接池参数 -->
    <property name="driverClass" value="${db.driver}"></property>
    <property name="jdbcUrl" value="${db.url}"></property>
    <property name="user" value="${db.username}"></property>
    <property name="password" value="${db.password}"></property>
    </bean>

    <!-- 6、声明式事务 bean -->
    <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!--
    6、aop 切面 bean 配置
    expression:根据指定的表达式选择要切入的位置
    id:切面标签的 id
    <aop:aspect>:用于配置事务的前置操作和后置操作,但是在该情景下不适用
    <aop:advisor>:通知需要执行的事务
    advice-ref:引入事务通知
    pointcut-ref:引入切入点
    -->
    <!-- <aop:config>
    <aop:pointcut expression="execution(* com.yidu.foodfresh.dao.impl.*.*(..))" id="mypointcut"/>
    <aop:advisor advice-ref="txadvice" pointcut-ref="mypointcut"/>
    </aop:config> -->

    <!-- 基于注解声明式事务完成事务的切面 -->
    <!-- <tx:annotation-driven transaction-manager="dataSourceTransactionManager"/> -->

    <!-- 基于上下文扫描组件 -->
    <context:component-scan base-package="com.ssm.*"></context:component-scan>

    </beans>

  • 相关阅读:
    nosql数据库:mongodb,redis,memcached,其优缺点和使用应用场景
    进程和线程的定义和区别
    PHP中的 抽象类(abstract class)和 接口(interface)
    简单理解php的socket编程
    session跨域共享解决方案
    MySQL 对于千万级的大表要怎么优化
    关于存session,cookie还是数据库或者memcache的优劣,部分网上抄录
    MYSQL 索引类型、什么情况下用不上索引、什么情况下不推荐使用索引
    MySQL把一个大表拆分多个表后,如何解决跨表查询效率问题
    PHP + NGINX 控制视频文件播放,并防止文件下载
  • 原文地址:https://www.cnblogs.com/4AMLJW/p/ssm_ljw_201909091527.html
Copyright © 2011-2022 走看看