Добрый день. Пишу контроллер, который будет через каждое время отправлять по вебсокету на фронтенд данные. Вот этот контроллер:
@RestController
@EnableScheduling
@RequestMapping(value = "/task")
public class TaskController {
@Scheduled(fixedRate = 5000)
public void getTaskForNotification() {
List l = taskService.getTaskForNotification(sessionUser.getGuid());
this.simpMessagingTemplate.convertAndSendToUser(userDao.getUserByGuid(sessionUser.getGuid()).getLogin(),"/queue/getTaskForNotification", l);
}
}
sessionUser то бин с session scope:
@Bean(name = "sessionUser")
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public SystemUser getSystemUser(){
return new SystemUser();
}
Проблема в том, что при попытке обратится к этому бину вылетает ошибка:
Error creating bean with name 'scopedTarget.sessionUser': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
Всё остальное работает. Подскажите, кто в курсе, как это можно пофиксить.
UserIDАпостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости