[英]Spring Jedis connection not returned to pool
我的应用程序由Spring rest控制器组成,该控制器使用Redis调用服务。 我正在使用spring boot starter redis 1.2.5,并且在我的beans.xml文件中定义了一个模板:
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${spring.redis.host}"
p:use-pool="true"
p:port="${spring.redis.port}"
/>
<bean id="redisTemplateForTransaction" class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnectionFactory"
p:keySerializer-ref="stringRedisSerializer"
p:valueSerializer-ref="jsonRedisSerializerForTransaction"
p:enableTransactionSupport="true">
<qualifier value="redisTemplateForTransaction" />
</bean>
当我启动8个以上的查询时,我的应用程序块将停止。 我了解我已达到池中的默认连接数。
为什么在请求处理结束时没有自动返回连接?
如何在事务模式下工作,以便任何传入请求都将获得其Redis连接并在处理结束时将其返回?
您需要通过提供PlatformTransactionManager
bean为您的应用程序启用事务管理。
最简单的方法是将@EnableTransactionManagement
添加到您的Spring Boot应用程序。 如果那不可能,请配置PlatformTransactionManager
bean。 重用现有的DataSourceTransactionManager
是最简单的方法。 如果不使用兼容JDBC的数据库,只需放入H2内存数据库。
如果要使用JTA事务管理器,请参阅此博客文章: https : //spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/
HTH,马克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.