0

I have list of names for bean to be created.

List<String> beanNames = getNames();

And I want to create Spring beans on loop with this names;

This is bean that I want to create.

@Bean(“beanName”)//bean name must be iterated value of beanNames
public RedisConnectionFactory connectionFactory() {
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(getHost());
    jedisConnectionFactory.setPort(getPort());
    jedisConnectionFactory.afterPropertiesSet();
    return jedisConnectionFactory;
}

And then I want to get any RedisConnectionFactory by name like :

RedisConnectionFactory rcf = applicationContext.getBean(“a name from beanNames list");

İs that possible?

sam
  • 1,073
  • 4
  • 13
  • 27
  • you should consider pooling capability instead of autowiring bean. connectionFactory which has connection pooling capability by default.https://stackoverflow.com/questions/44569901/use-connection-pool-with-jedis – CodeIsLife Jul 26 '18 at 20:21
  • @CodeIsLife my main problem is https://stackoverflow.com/questions/51545572/spring-data-redis-with-multi-tenancy . I have been trying to implement multitenancy. – sam Jul 26 '18 at 20:23
  • answered here https://stackoverflow.com/a/51547333/2371309 – CodeIsLife Jul 26 '18 at 20:51

0 Answers0