欢迎投稿

今日深度:

mybatis sqlite 配置,mybatissqlite配置

mybatis sqlite 配置,mybatissqlite配置


<context:annotation-config />
<context:component-scan base-package="com.ins">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>

<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">   
    <property name="dataSource" ref="dataSource"></property>
  </bean>

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
<property name="locations">  
<list>  
                 <value>/WEB-INF/classes/dbconfig.properties</value>  
            </list>  
        </property>  
</bean> 

<!-- 阿里 druid数据库连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"  init-method="init" destroy-method="close">  
         <!-- 数据库基本信息配置 -->
         <property name="dbType" value="${dbType}"></property>  
         <property name="url" value="${url}" />  
         <property name="username" value="${username}" />  
         <property name="password" value="${password}" />  
         <property name="driverClassName" value="${driverClassName}" />  
         <property name="filters" value="${filters}" />  
    <!-- 最大并发连接数 -->
         <property name="maxActive" value="${maxActive}" />
         <!-- 初始化连接数量 -->
         <property name="initialSize" value="${initialSize}" />
         <!-- 配置获取连接等待超时的时间 -->
         <property name="maxWait" value="${maxWait}" />
         <!-- 最小空闲连接数 -->
         <property name="minIdle" value="${minIdle}" />  
    <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
         <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />
         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
         <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" />  
         <property name="validationQuery" value="${validationQuery}" />  
         <property name="testWhileIdle" value="${testWhileIdle}" />  
         <property name="testOnBorrow" value="${testOnBorrow}" />  
         <property name="testOnReturn" value="${testOnReturn}" />  
         <!-- 
         <property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements}" />
          -->
         <!-- 打开removeAbandoned功能 -->
         <property name="removeAbandoned" value="${removeAbandoned}" />
         <!-- 1800秒,也就是30分钟 -->
         <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" />
         <!-- 关闭abanded连接时输出错误日志 -->   
         <property name="logAbandoned" value="${logAbandoned}" />
</bean>  

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED" read-only="false" 
          rollback-for="java.lang.Exception"/>
<tx:method name="insert*" propagation="REQUIRED" read-only="false" 
          rollback-for="java.lang.Exception" />
<tx:method name="update*" propagation="REQUIRED" read-only="false" 
          rollback-for="java.lang.Exception" />
<tx:method name="save*" propagation="REQUIRED" read-only="false" 
          rollback-for="java.lang.Exception" />
</tx:attributes>
</tx:advice>

<aop:aspectj-autoproxy proxy-target-class="true"/>

<!-- 事物处理 -->
<aop:config>
<aop:pointcut id="pc" expression="execution(* com.ins.service..*(..))" />
<aop:advisor pointcut-ref="pc" advice-ref="txAdvice" />
</aop:config>

<!-- 配置mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
        <!-- mapper扫描 -->
        <property name="mapperLocations" value="classpath:mybatis/*/*.xml"></property>
    </bean>
    
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />

</bean>



dbType=sqlite  
driverClassName=org.sqlite.JDBC  
#url=jdbc:sqlite::resource:data/sysdat.db  
url=jdbc:sqlite:e:/sysdat.db
username=  
password=  
       
#filters:stat
   
filters:log4j
maxActive:20
initialSize:10
maxWait:60000
minIdle:10
maxIdle:15
   
timeBetweenEvictionRunsMillis:60000
#minEvictableIdleTimeMillis:300000
minEvictableIdleTimeMillis:25200000
   
validationQuery:SELECT 'x'
testWhileIdle:true
testOnBorrow:false
testOnReturn:false


maxOpenPreparedStatements:20
removeAbandoned:true
removeAbandonedTimeout:1800
logAbandoned:true


注意事项:

<property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements}" /> 需要设置为0 或者注释掉否则报 resultset  closed 异常

数据库文件不要放入 classes 文件夹下以免引发tomcat 重启

www.htsjk.Com true http://www.htsjk.com/SQLite/36068.html NewsArticle mybatis sqlite 配置,mybatissqlite配置 context:annotation-config / context:component-scan base-package="com.ins" context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" / /context:component-scan...
相关文章
    暂无相关文章
评论暂时关闭