ssm项目,如何在websocket中使用service

xu.wang

发布于 2018.08.27 21:07 阅读 2787 评论 0

    在项目中,由于Excel文件过大,使用http会出现超时的现象,所以使用websocket来生成Excel,文件生成时可自动返回文件地址,使用起来比较方便。

    但是由于在websocket中需要使用到service,所以打算使用
 

@Resource
private UserService userService;

 来获取到service,但是发现最终 userService == null;

 这个问题怎么解决呢?

1. 使用

ContextLoader.getCurrentWebApplicationContext().getBean(BeanName.class);

例如:

private CustomerService customerService  = ContextLoader.getCurrentWebApplicationContext().getBean(CustomerService.class);