Bean and Annotations with Generics, how to do?

2

I'm in a project with Spring 4 configuring Redis and a construction like this came up:

@Configuration
@ComponentScan({"com.empresa.sistema.web.util"})
public class RedisConfig {
    @Bean
    public RedisTemplate<String, Object> redisTemplate() {
        RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setKeySerializer(stringRedisSerializer());
        template.setHashKeySerializer(stringRedisSerializer());
        return template;
    }
}

It works perfectly, but now I wanted to do something like this:

@Bean
public RedisTemplate<String, T> redisTemplate() {
    RedisTemplate<String, T> template = new RedisTemplate<String, T>();
    template.setConnectionFactory(jedisConnectionFactory());
    template.setKeySerializer(stringRedisSerializer());
    template.setHashKeySerializer(stringRedisSerializer());
    return template;
}

How can I do this?

    
asked by anonymous 30.05.2017 / 19:33

0 answers