Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2222

How to configure @Transactional support to Redis in Springboot?

$
0
0

I am currently working on a project which is using Redis mainly for caching purposes, I am using Oracle as the main database and Spring Data JPA to handle the database layer in my project. I need to know how to use @Transactional annotation support to handle transactions in Redis. I have already referred to lots of tutorials and documentation regarding this scenario. In most of those tutorials, there is always the same set of source codes available. But still, I didn't have a clear idea about the implementation. Because in my application there is already a data source available which I configured through property file. (Oracle database) So I doubt the implementation of the dataSource bean. And I couldn't understand the usage of transactionManager bean too. How should I implement this properly please give a detailed explanation.

Source code which I found on the internet.

@Configuration@EnableTransactionManagement // 1public class RedisConfig {    @Bean    public StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory redisConnectionFactory) {        // Configure redisTemplate        StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();        stringRedisTemplate.setConnectionFactory(redisConnectionFactory);        / / Open transaction support        stringRedisTemplate.setEnableTransactionSupport(true); // 2        return stringRedisTemplate;    }    @Bean    public PlatformTransactionManager transactionManager() throws SQLException {        return new DataSourceTransactionManager(dataSource()); // 3    }    @Bean    public DataSource dataSource() throws SQLException {        // ...    }}

Viewing all articles
Browse latest Browse all 2222

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>