注册

SSM框架 spring配置文件
首页 > IT计算机 > Java    作者:RainFly   2018年4月18日 15:15 星期三   热度:14759°   字号:   评论:5    
时间:2018-4-18 15:15   热度:14759°  评论:5 条 
<?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"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 
 
<!--  spring的配置文件  一般写入数据源     事务控制    mybatis扫描 mapper 文件中  IOC控制器中  -->



 <!-- 扫描service 层下面所有的 @Server  加入ICO容器中   -->
    <context:annotation-config />
 <context:component-scan base-package="com.rain.service" />
 
 
 
  <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
         <!-- 基本属性 url、user、password -->
         <property name="url" value="jdbc:mysql://localhost:3306/power?characterEncoding=UTF-8" />
         <property name="username" value="root" />
         <property name="password" value="root" />
         <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  
         <!-- 配置初始化大小、最小、最大 -->
         <property name="initialSize" value="3" />
         <property name="minIdle" value="3" />
         <property name="maxActive" value="20" />
  
         <!-- 配置获取连接等待超时的时间 -->
         <property name="maxWait" value="60000" />
  
         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
         <property name="timeBetweenEvictionRunsMillis" value="60000" />
  
         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
         <property name="minEvictableIdleTimeMillis" value="300000" />
  
         <property name="validationQuery" value="SELECT 1" />
         <property name="testWhileIdle" value="true" />
         <property name="testOnBorrow" value="false" />
         <property name="testOnReturn" value="false" />
  
         <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
         <property name="poolPreparedStatements" value="true" />
         <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
  </bean>
 

 
<!--  mybatis 和spring 进行整合  -->
   <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="typeAliasesPackage" value="com.rain.pojo" />
        <property name="dataSource" ref="dataSource"/>
        <!--    指定mybatis mapper文件的地址 -->
        <property name="mapperLocations" value="classpath:com/rain/mapper/*.xml"/>
        
        
        <property name="plugins">
            <array>
             <!-- pagehelper -->
              <bean class="com.github.pagehelper.PageInterceptor">
                <property name="properties">
                  <!--使用下面的pagehelper方式配置参数,一行配置一个 -->
                  <value>
                  </value>
                </property>
              </bean>
            </array>
          </property>   
        
    </bean>
    
 <!--  配置扫描器  将 mybatis 接口的实现加入 ioc 容器中  -->
 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
      <!-- 扫描 该包路径下 所有 DAO接口的实现 加入 到 IOC容器中  -->
 <property name="basePackage" value="com.rain.mapper"/>
 </bean>
 

    <!-- 配置spring的PlatformTransactionManager,名字为默认值 -->  
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource" />  
    </bean>  
      
    <!-- 开启事务控制的注解支持   比较多的使用 xml配置形式的事务-->  
    <aop:config>
     <!-- 切入点表达式  -->
     <aop:pointcut expression="execution(* com.rain.service..*(..))" id="txPoint"/>
     <!-- 事务增强 -->
     <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
    </aop:config>
    
    <!-- 配置事务增强  如何切入  -->
    <tx:advice id="txAdvice">
     <tx:attributes>
     <!-- 所有方法都是事务方法 -->
     <tx:method name="*" />
     <!-- 以get开始的所有方法 -->
     <tx:method name="get*" read-only="true"/>
     </tx:attributes>
     
     <!--  spring配置文件核心点    数据源   与mybatis 整合     -->
    </tx:advice>
    
    

</beans>
  您阅读这篇文章共花了:  
捐赠支持:如果觉得这篇文章对您有帮助,请 "扫一扫"鼓励作者!
二维码加载中...
本文作者:RainFly      文章标题: SSM框架 spring配置文件
本文地址:http://www.rainfly.cn/?post=314
版权声明:若无注明,本文皆为“雨夜轩”原创,转载请保留文章出处。

已有5条吐槽

长沙麻将单机  Google Chrome 49.0.2623.110 Google Chrome 49.0.2623.110 Windows 10 Windows 10  2019-03-28 10:21 #4楼
文章写得很好。
RainFly  Google Chrome 66.0.3359.139 Google Chrome 66.0.3359.139 Windows 10 Windows 10  2018-07-11 23:48 地板
ceshi1
武胜婚庆公司  Firefox 59.0 Firefox 59.0 Windows 7 Windows 7  2018-04-23 10:33 板凳
这篇文章写得很好。
跨境电商教程 Firefox 50.0 Firefox 50.0 Windows 10 Windows 10  2018-04-29 23:47
@武胜婚庆公司:纯顶。不过内容很好
武胜  Firefox 59.0 Firefox 59.0 Windows 7 Windows 7  2018-04-23 10:32 沙发
文章很好值得一看。

QQ游客评论

返回顶部    首页    捐赠支持    手气不错    友情链接    关于我们    站长工具    站长介绍    手机版本    后台登陆   
版权所有:雨夜轩    站长:RainFly    特别鸣谢   文章归档   皖ICP备15003600号-1   百度统计
Copyright©2015 雨夜轩 Powered by emlog强力驱动 七牛CDN全球加速 360站长联盟安全认证 中国博客联盟荣誉成员 可信赖网站 站点地图   
页面加载耗时:0.042秒 数据库查询次数:21次
背景设置