websocket 中使用Service层的方法
创建公共Utils 类
ApplicationContextRegister
@Component
@Lazy(false)
public class ApplicationContextRegister implements ApplicationContextAware {
private static ApplicationContext APPLICATION_CONTEXT;
/**
* 设置spring上下文 * * @param applicationContext spring上下文 * @throws BeansException *
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
APPLICATION_CONTEXT = applicationContext;
}
public static ApplicationContext getApplicationContext() {
return APPLICATION_CONTEXT;
}
}
使用Util
//websocket 使用service 层
ApplicationContext act = ApplicationContextRegister.getApplicationContext();
messagelogService=act.getBean(MessagelogService.class);
int resultlog = messagelogService.insertIntoMessagelog(messagelog);