1

the code as below:

@Controller

public class MapEventHandler implements EventHandler{

@Resource
VisitorMacService visitorMacService;

@RequestMapping("/maptest")
@ResponseBody
public String maptest(){
    return "maptest";
}

@Override
public void onEvent(MapEvent event, long sequence, boolean endOfBatch) throws Exception {
    // TODO Auto-generated method stub
    visitorMacList = visitorMacService.getAllMacList();
}

} when visited the url "localhost:8080/maptest", the bean "visitorMacService" can be generated automatically. But when data is putted in the ringBuffer, executing the method of "onEvent()" automatically, the bean "visitorMacService" is null. why? Can someone help?

Spring version: 4.0.2 lmax disruptor version: 3.2.1

jaafar
  • 11
  • 2
  • Why is it a `@Controller`? and not a normal `@Component`? It has nothing to do with being a web based controller. Also is this bean even a spring managed bean? You are using LMAX so I suspect somewhere a `new MapEventHandler()` is done instead of using a spring managed instance. – M. Deinum Feb 06 '17 at 14:57
  • Thank for your help. Even it is a normal @Component, the question still likes this. Not nothing to do ,here for explain this question simply, I delete other codes. The bean is generated by automatic scanning. – jaafar Feb 07 '17 at 00:46
  • As I stated the bean CANNOT be created by spring else the field wouldn't be `null` (also making a component and event handler is not the best design I would say). So you are creating a new instance somewhere and that isn't a spring managed instance. – M. Deinum Feb 07 '17 at 06:39
  • Thank you for your help. I've find the answer: the method of Disruptor is multi-thread, but for the safe, Spring disallows the @Autowired annotation in multi-thread. And the design of my project is truely not a good example. – jaafar Feb 08 '17 at 00:48

0 Answers0