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;
- }
- }
- //websocket 使用service 层
- ApplicationContext act = ApplicationContextRegister.getApplicationContext();
- messagelogService=act.getBean(MessagelogService.class);
- int resultlog = messagelogService.insertIntoMessagelog(messagelog);
即可使用到service里的方法了!!
websocket 中使用Service层的方法的更多相关文章
- SpringBoot:WebSocket使用Service层的方法
方法一: 创建工具类 ApplicationContextRegister.java import org.springframework.beans.BeansException; import o ...
- 【spring data jpa】使用spring data jpa时,关于service层一个方法中进行【删除】和【插入】两种操作在同一个事务内处理
场景: 现在有这么一个情况,就是在service中提供的一个方法是先将符合条件的数据全部删除,然后再将新的条件全部插入数据库中 这个场景需要保证service中执行两步 1.删除 2.插入 这两步自然 ...
- 在Java filter中调用service层方法
在项目中遇到一个问题,在 Filter中注入 Serivce失败,注入的service始终为null.如下所示: public class WeiXinFilter implements Filter ...
- 浅谈MVC中的service层(转)
概述 mvc框架由model,view,controller组成,执行流程一般是:在controller访问model获取数据,通过view渲染页面. mvc模式是web开发中的基础模式,采用的是分层 ...
- (网页)websocket后台调用Service层
百度论坛里面有很多好的方法,借鉴. 重点:因为项目是StringBoot所以我用的是下面的方法很好使: Service.... service = (Service....) ContextLoade ...
- [转]servlet中的service, doGet, doPost方法的区别和联系
原文地址:http://m.blog.csdn.net/blog/ghyg525/22928567 大家都知道在javax.servlet.Servlet接口中只有init, service, des ...
- SpringBoot在自定义类中调用service层等Spring其他层
解决方案: 1.上代码 @Component public class ServerHandler extends IoHandlerAdapter { @Autowired protected He ...
- Spring main方法中怎么调用Dao层和Service层的方法
在web环境中,一般serviceImpl中的dao之类的数据库连接都由容器启动的时候创建好了,不会报错.但是在main中,没有这个环境,所以需要获取环境: ApplicationContext ct ...
- 事物处理service层的方法
package cn.lijun.service; import java.sql.Connection;import java.sql.SQLException; import cn.lijun.d ...
随机推荐
- vue中路由传参的方式
一.params的类型: 配置路由格式: /router/:id 传递的方式: 在path后面跟上对应的值 传递后形成的路径: /router/123, /router/abc 通过:to字符串拼接的 ...
- Python3 使用HTMLTestRunner.py 报错ImportError: No module named 'StringIO'处理方法
HTMLTestRunner.py文件是基于Python2的语法,python3使用需要修改语法: 1.>>> 94行 import io # import StringIO 2.& ...
- Python3解leetcode Binary Tree Paths
问题描述: Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. E ...
- JS中关于数组的操作
1.如何创建数组: var arr = []; //效率更高 var arr1 = new Array(); var arr2 = new Array(5); //数组的长度为5,当参数为一个时,将会 ...
- EasyUI 中的双击某行 并赋值给input事件
项目是由mvc+easyUI开发,双击事件在下边.有注释写着呢 function DataList(supCode) { myDatagrid2.datagridId = "GridView ...
- 术语-Portal:Portal(Web站点)
ylbtech-术语-Portal:Portal(Web站点) Portal作为网关服务于因特网的一种WEB站点.Portal是链路.内容和为用户可能找到的感兴趣的信息(如新闻.天气.娱乐.商业站点. ...
- nginx 配置代理 session 丢失
最开始一直用的ip访问的项目是没问题的 , 后来改成用了域名访问就发现一直获取不了session ,最开始以为是跨域问题 , 但项目中已经配置了跨域 , 因为第一次用 nginx ,果断入坑了 , ...
- js对象传到后台ACTION使用
需的包 <script type="text/javascript" src="s"></script>gson-1.2.3.jar谷歌 ...
- sizeof 运算结果与编译系统有关
研究与实现相关的layout没多大意义 参考:有关c++中类的虚拟继承sizeof问题 情况1:<剑指offer>纪念版题,sizoef(空类)的结果? class A{}; sizeof ...
- java 异常处理try+catch
在整个异常处理机制中,异常在系统中进行传递,传递到程序员认为合适的位置,就捕获到该异常,然后进行逻辑处理,使得项目不会因为出现异常而崩溃.为了捕获异常并对异常进行处理,使用的捕获异常以及处理的语法格式 ...