My app is made of a Spring rest controller calling a service using redis. I am using spring boot starter redis 1.2.5 and I have defined a template in my beans.xml file:
<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>
When I launch more than 8 queries my app blocks. I understand I have reached the default number of connections in the pool.
Why aren't the connections returned automatically at the end of the request processing ?
How to work in a transactional mode so that any incoming request will get its redis connection and return it at the end of the processing ?
You need to enable transaction management for your application by providing a PlatformTransactionManager
bean.
The easiest way to do so is adding @EnableTransactionManagement
to your Spring Boot application. If that's not possible, configure a PlatformTransactionManager
bean. Reusing an existing DataSourceTransactionManager
is the easiest way. If you do not use a JDBC-compliant database, simply drop in a H2 in-memory database.
If you want to use a JTA transaction manager, see this blog post: https://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/
HTH, Mark
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With