春天配置多数据源切换

  

<强>多数据源切换

  

db.properties         # MySQL   jdbc.driver=com.mysql.jdbc.Driver   jdbc.url=jdbc: mysql://localhost: 3306/测试# 63;autoReconnect=true& characterEncoding=utf - 8   jdbc.username=根   jdbc.password=admin   #定义初始连接数   initialSize=0   #定义最大连接数   maxActive=1000   #定义最大空闲   maxIdle=20   #定义最小空闲   minIdle=1   #定义最长等待时间   maxWait=60000   # MySQL   # driverClassName根据url自动识别这一项可配可不配,如果不配置德鲁伊会根据url自动识别dbType,然后选择相应的driverClassName   jdbc.driver1=com.mysql.jdbc.Driver   jdbc.url1=jdbc: mysql://localhost: 3306/test1 # 63; allowMultiQueries=true& autoReconnect=true& characterEncoding=utf - 8   jdbc.username1=根   jdbc.password1=admin   #初始化时建立物理连接的个数。初始化发生在显示调用初始化方法,或者第一次getConnection时   initialSize1=0   #最大连接池数量   maxActive1=1000   #定义最小空闲   minIdle1=1   #获取连接时最大等待时间,单位毫秒。配置了maxWait之后,   #缺省启用公平锁,并发效率会有所下降,   #如果需要可以通过配置useUnfairLock属性为真正的使用非公平锁。   maxWait1=60000   #德鲁伊监控   #属性类型是字符串,通过别名的方式配置扩展插件,   #常用的插件有:   #监控统计用的过滤器:统计   #日志用的过滤器:log4j   #防御sql注入的过滤器:墙   filters1=统计,log4j   #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒   timeBetweenEvictionRunsMillis1=60000   #配置一个连接在池中最小生存的时间,单位是毫秒   minEvictableIdleTimeMillis1=300000   #建议配置为真,不影响性能,并且保证安全性。   #申请连接的时候检测,如果空闲时间大于   # timeBetweenEvictionRunsMillis,   #执行validationQuery检测连接是否有效。   testWhileIdle1=true   #申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。   testOnBorrow1=false   #归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能   testOnReturn1=false   #是否缓存preparedStatement,也就是PSCache。   # PSCache对支持游标的数据库性能提升巨大,比如说甲骨文。   #在mysql5.5以下的版本中没有PSCache功能,建议关闭掉。   #作者在5.5版本中使用PSCache,通过监控界面发现PSCache有缓存命中率记录,   #该应该是支持PSCache。   poolPreparedStatements1=false   #要启用PSCache,必须配置大于0,当大于0时,   # poolPreparedStatements自动触发修改为真实的。   #在德鲁伊中,不会存在甲骨文下PSCache占用内存过多的问题,   #可以把这个数值配置大一些,比如说100   maxOpenPreparedStatements1=1      

<强>中

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;豆类xmlns=" http://www.springframework.org/schema/beans "   xmlns: xsi=" http://www.w3.org/2001/XMLSchema-instance "   xmlns:上下文=" http://www.springframework.org/schema/context "   xmlns: tx=" http://www.springframework.org/schema/tx "   xmlns: websocket=" http://www.springframework.org/schema/websocket "   xsi: schemaLocation="   http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd   http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context.xsd   http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx.xsd   http://www.springframework.org/schema/websocket   http://www.springframework.org/schema/websocket/spring-websocket.xsd”比;   & lt; !——春天使用注解配置扫描com。y下的扫描但是在springmvc里边已经扫描一次了   这时就要加上属性use-default-filters=" true "这个属性就是使用默认的扫描   默认就扫描com。y下所有设置为假在下边配置需要扫描的部分,比;   & lt; !——现在的配置就只会扫描带@ @ service和注解的类——比;   & lt;上下文:component-scan基础包=癱om”use-default-filters=癴alse”比;   & lt; !——org.springframework.stereotype。服务就是注解@ Service这个注解使用在服务里所以就是扫描服务包   org.springframework.stereotype。库库仓库——比;   & lt;上下文:include-filter type==皁rg.springframework.stereotype.Controller”/白⑹汀北泶锉?   & lt;上下文:include-filter type==皁rg.springframework.beans.factory.annotation.Autowired”/白⑹汀北泶锉?   & lt;上下文:include-filter type==皁rg.springframework.stereotype.Service”/白⑹汀北泶锉?   & lt;上下文:include-filter type==皁rg.springframework.stereotype.Repository”/白⑹汀北泶锉?   & lt;/背景:component-scan>   & lt; !——读取属性文件——比;   & lt; bean id=皃ropertyConfigurer”类=皁rg.springframework.beans.factory.config.PropertyPlaceholderConfigurer”比;   & lt;属性名="位置"比;   & lt; list>   & lt; value>类路径:db.properties

春天配置多数据源切换