How to create a second RedisTemplate instance in a Spring Boot application
<p>According to <a href="https://stackoverflow.com/a/21857931/550283">this answer</a>, one <code>RedisTemplate</code> cannot support multiple serializers for values. So I want to create multiple RedisTemplates for different needs, specifically one for string actions and one for object to JSON serializations, to be used in <code>RedisCacheManager</code>. I'm using Spring Boot and the current <code>RedisTemplate</code> is autowired, I'm wondering what's the correct way to declare a second <code>RedisTemplate</code> instance sharing the same Jedis connection factory but has its own serializers?</p>

<p>Tried something like this in two different components,</p>

<p>Component 1 declares,</p>

<pre><code>    @Autowired
    private RedisTemplate redisTemplate;

    redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer(Instance.class));
</code></pre>

<p>Component 2 declares,</p>

<pre><code>    @Autowired
    private StringRedisTemplate stringRedisTemplate;
</code></pre>

<p>In this case the two templates actually are the same. Traced into Spring code and found component 1's template got resolved to autoconfigured <code>stringRedisTemplate</code>.</p>

<p>Manually calling <code>RedisTemplate</code>'s contructor and then its <code>afterPropertiesSet()</code> won't work either as it complains no connection factory can be found.</p>

<p>I know this request probably is no big difference from defining another bean in a Spring app but not sure with the current Spring-Data-Redis integration what's the best way for me to do. Please help, thanks.</p>