mor*_*hai 6 java spring spring-mvc redis spring-transactions
我的应用程序是由Spring休息控制器使用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>
Run Code Online (Sandbox Code Playgroud)
当我启动超过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,马克
归档时间: |
|
查看次数: |
946 次 |
最近记录: |