配置双数据源出错,求大神

zcs8477955 zcs8477955 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<?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:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">


<context:annotation-config />
<!-- 自动扫描Dao -->
<context:component-scan base-package="com.yunyueweixin.dao"></context:component-scan>

<!-- 自动扫描Service -->
<context:component-scan base-package="com.yunyueweixin.services"></context:component-scan>

<!-- 自动扫描Action -->
<context:component-scan base-package="com.yunyueweixin.action"></context:component-scan>




<!-- 配置数据源 -->
<context:property-placeholder
location="classpath:druid.properties,classpath:redis.properties" />
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!-- 数据库基本信息配置 -->
<property name="driverClassName" value="${druid.driverClassName}" />
<property name="url" value="${druid.url}" />
<property name="username" value="${druid.username}" />
<property name="password" value="${druid.password}" />
<property name="connectionInitSqls" value="${druid.initConnectionSqls}" />
<!-- 初始化连接数 -->
<property name="initialSize" value="${druid.initialSize}" />
<!-- 最小空闲连接数 -->
<property name="minIdle" value="${druid.minIdle}" />
<!-- 最大并发连接数 -->
<property name="maxActive" value="${druid.maxActive}" />
<!-- 配置获取连接等待超时的时间,单位是毫秒 -->
<property name="maxWait" value="${druid.maxWait}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" />
<property name="validationQuery" value="${druid.validationQuery}" />
<property name="testWhileIdle" value="${druid.testWhileIdle}" />

<property name="testOnBorrow" value="${druid.testOnBorrow}" />
<property name="testOnReturn" value="${druid.testOnReturn}" />

<!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用) <property name="poolPreparedStatements"
value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize"
value="20" /> -->
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="${druid.filters}" />
</bean>

<!-- 配置Jdbc模板 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>

<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!--5 采用@Transactional注解方式使用事务 -->
<tx:annotation-driven transaction-manager="txManager" />

<!-- 配置oracle数据源开始 -->
<bean id="dataSourceOracle" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!--数据库基本信息配置 -->
<property name="driverClassName" value="${druid.driverClassNameForOracle}" />
<property name="url" value="${druid.urlForOracle}" />
<property name="username" value="${druid.usernameForOracle}" />
<property name="password" value="${druid.passwordForOracle}" />
<property name="connectionInitSqls" value="${druid.initConnectionSqls}" />
<!--初始化连接数 -->
<property name="initialSize" value="${druid.initialSize}" />
<!--最小空闲连接数 -->
<property name="minIdle" value="${druid.minIdle}" />
<!--最大并发连接数 -->
<property name="maxActive" value="${druid.maxActive}" />
<!--配置获取连接等待超时的时间,单位是毫秒 -->
<property name="maxWait" value="${druid.maxWait}" />
<!--配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" />
<!--配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" />
<property name="validationQuery" value="${druid.validationQuery}" />
<property name="testWhileIdle" value="${druid.testWhileIdle}" />

<property name="testOnBorrow" value="${druid.testOnBorrow}" />
<property name="testOnReturn" value="${druid.testOnReturn}" />

<!--打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用) -->
<property name="poolPreparedStatements"
value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize"
value="20" />
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="${druid.filters}" />
</bean>
<!-- 配置Jdbc模板 -->
<bean id="jdbcTemplateOracle" class="org.springframework.jdbc.core.JdbcTemplate" >
<property name="dataSource" ref="dataSourceOracle"></property>
</bean>
<bean id="txManagerOracle"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceOracle" />
</bean>
<!--5 采用@Transactional注解方式使用事务 -->
<tx:annotation-driven transaction-manager="txManagerOracle" />
<!-- 配置oracle数据源结束 -->


<!-- redis配置 -->
<bean id="redisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.pool.maxIdle}" /> <!-- 最大能够保持idel状态的对象数 -->
<property name="maxTotal" value="${redis.pool.maxTotal}" /> <!-- 最大分配的对象数 -->
<property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" /> <!-- 当池内没有返回对象时,最大等待时间(毫秒) -->
<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" /> <!-- 当调用borrow Object方法时,是否进行有效性检查 -->
</bean>
<bean id="redisConFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.ip}" />
<property name="port" value="${redis.port}" />
<property name="password" value="${redis.password}" />
<property name="usePool" value="true" />
<property name="poolConfig" ref="redisPoolConfig" />
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConFactory" />
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="HashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"></bean>
</property>
<property name="HashValueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"></bean>
</property>
</bean>

</beans>


...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
zcs8477955
Oracle 17,133 成员 55,258 内容