websocket 中使用Service层的方法

查找后记录下使用方法:

 创建公共Utils 类    

ApplicationContextRegister  
@Component
@Lazy(false)
public class ApplicationContextRegister  implements ApplicationContextAware {
    private static ApplicationContext APPLICATION_CONTEXT;

    /**
     * 设置spring上下文  *  * @param applicationContext spring上下文  * @throws BeansException  * author:huochengyan https://blog.csdn.net/u010919083
     */

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        APPLICATION_CONTEXT = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return APPLICATION_CONTEXT;
    }
}

  //websocket 使用service 层
                ApplicationContext act = ApplicationContextRegister.getApplicationContext();
                messagelogService=act.getBean(MessagelogService.class);
                int resultlog = messagelogService.insertIntoMessagelog(messagelog);

  即可使用到service里的方法了!!

  有的小伙伴回复还是不太明白:截图说明:

注意:要是还不明白的话 扫码提问吧,哈哈。



猜你喜欢

转载自blog.csdn.net/u010919083/article/details/79388720