1

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 ?

1 Answers1

0

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

Anton Khoff
  • 16
  • 1
  • 5
  • a bit late for me, but thanks for responding, i moved on to quartz anyway –  Apr 17 '20 at 02:48
  • 1
    I have actually done that but still getting the bean not found. Config config = new Config(); config.useSingleServer().setAddress("redis://" + redisHost + ":" + redisPort + ""); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 1)); nodeConfig.setBeanFactory(beanFactory); RedissonNode node = RedissonNode.create(nodeConfig); node.start(); return node; – Shuja Ahmed Jun 29 '20 at 20:00