Search code examples
redisredisson

Redisson config setBeanFactory autowiring beans


I have a task class defined here:

{

    @Autowired
    private CarPainter carpainter;

    private String color;
    private Car car;


    public CarPainterTask(Car car, String color)
    {
        this.car = car;
        this.color = color;
    }


    public Car call()
    {

        if(car.getColor().equals(color))
        {
            return car;
        }

    carPainter.paint(car);  

        return car;
    }

}

I want to be able to @Autowired a service into my task class but also be able to put in some parameters

I've tried creating a @Configuration class for my Redisson node

    @Bean
    public RedissonNode createRedissonWorker()
    {
        RedissonNodeConfig nodeConfig = new RedissonNodeConfig(redissonClient.getConfig());
        nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("carService", 1));
        nodeConfig.setBeanFactory(applicationContext);
        RedissonNode node = RedissonNode.create(nodeConfig);
        node.start();
        return node;
    }

And having Redisson inject CarPainter bean from Springboot's bean container, but this doesn't work...

Is there a way to achieve what I need here ?


Solution

  • In your createRedissonWorker() method use the BeanFactory instance to pass it to setBeanFactory() instead of the ApplicationContext and it should work just fine.