zoukankan      html  css  js  c++  java
  • spring mvc+mybatis+sql server简单配置

    context.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:tx="http://www.springframework.org/schema/tx"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
    
        <context:component-scan base-package="com.jxyq" use-default-filters="false">
            <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
        </context:component-scan>
    
        <bean id="springContextHolder" class="com.jxyq.config.SpringContextHolder"/>
    
        <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="fileEncoding" value="UTF-8"/>
            <property name="locations">
                <array>
                    <value>classpath:proxool.properties</value>
                    <value>classpath:security.properties</value>
                    <value>classpath:systemParam.properties</value>
                </array>
            </property>
        </bean>
    
        <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename" value="messages"/>
        </bean>
    
        <!--第一个数据源-->
        <bean id="oneDataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
            <property name="alias" value="${proxool.alias}"/>
            <property name="driver" value="${proxool.driver}"/>
            <property name="user" value="${proxool.user}"/>
            <property name="password" value="${proxool.password}"/>
            <property name="driverUrl" value="${proxool.url}"/>
            <property name="trace" value="${proxool.trace}"/>
            <property name="prototypeCount" value="${proxool.prototypeCount}"/>
            <property name="maximumConnectionCount" value="${proxool.maximumConnectionCount}"/>
            <property name="minimumConnectionCount" value="${proxool.minimumConnectionCount}"/>
            <property name="simultaneousBuildThrottle" value="${proxool.simultaneousBuildThrottle}"/>
            <property name="houseKeepingTestSql" value="${proxool.houseKeepingTestSql}"/>
        </bean>
    
        <bean id="oneSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="oneDataSource"/>
            <property name="configLocation" value="classpath:mybatis.xml"/>
            <property name="mapperLocations">
                <list>
                    <value>classpath:mapper/*.xml</value>
                </list>
            </property>
            <property name="typeAliasesPackage" value="com.jxyq.model"/>
            <property name="plugins">
                <list>
                    <bean class="com.jxyq.commons.mybatis.pagination.PagingInterceptor">
                        <property name="dbModel" value="${proxool.dbModel}"/>
                        <property name="dialect">
                            <bean class="com.jxyq.commons.mybatis.pagination.dialect.OracleDialect"/>
                        </property>
                        <property name="sqlRegex" value=".*ByPage"/>
                    </bean>
                </list>
            </property>
        </bean>
    
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="oneDataSource"/>
        </bean>
    
        <bean id="oneTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="oneDataSource"/>
        </bean>
    
        <tx:annotation-driven transaction-manager="transactionManager"/>
    
        <bean id="oneTransactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
            <property name="transactionManager" ref="oneTransactionManager"/>
        </bean>
    
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="sqlSessionFactoryBeanName" value="oneSqlSessionFactory"></property>
            <property name="basePackage" value="com.jxyq.mapper"/>
        </bean>
    
        <bean id="oneResultMapManager" class="com.jxyq.config.ResultMapManager">
            <property name="sqlSessionFactory" ref="oneSqlSessionFactory"/>
        </bean>
    
        <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
            <property name="corePoolSize" value="3"/>
            <property name="maxPoolSize" value="5"/>
            <property name="queueCapacity" value="1000"/>
            <property name="keepAliveSeconds" value="60"/>
            <property name="rejectedExecutionHandler">
                <bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy"/>
            </property>
        </bean>
    
    </beans> 

    proxool.properties配置文件

    #SQLServer
    proxool.alias=mainDB
    proxool.dbModel=SQLServer
    proxool.driver=net.sourceforge.jtds.jdbc.Driver
    proxool.url=jdbc:jtds:sqlserver://193.160.17.251:1433;databasename=tempdb
    proxool.user=sa
    proxool.password=fnst1234
    proxool.trace=true
    proxool.prototypeCount=3
    proxool.maximumConnectionCount=100
    proxool.minimumConnectionCount=10
    proxool.simultaneousBuildThrottle=80
    proxool.houseKeepingTestSql=select current_date

    驱动(mavem):

            <dependency>
                <groupId>net.sourceforge.jtds</groupId>
                <artifactId>jtds</artifactId>
                <version>1.3.1</version>
            </dependency>

    一开始时使用微软官方的驱动sqljdbc4(com.microsoft.sqlserver),但是一直报找不到合适的驱动,最后就改用jtds开源的驱动替代。

  • 相关阅读:
    linux 下ip命令对比ifconfig命令
    Redis使用详细教程
    shell中eval命令
    在Ubuntu 14.04 上安装 FTP 服务
    这本将shell的书应该不错
    linux sh 脚本调用外部命令
    c语言char 和int的问题
    ubuntu网卡ip的配置
    js中获取时间new date()的用法
    react 组件之间的通信
  • 原文地址:https://www.cnblogs.com/maxiaofang/p/4800431.html
Copyright © 2011-2022 走看看