创建公共Utils 类

  1. ApplicationContextRegister
  1. @Component
  2. @Lazy(false)
  3. public class ApplicationContextRegister  implements ApplicationContextAware {
  4. private static ApplicationContext APPLICATION_CONTEXT;
  5. /**
  6. * 设置spring上下文  *  * @param applicationContext spring上下文  * @throws BeansException
  7. */
  8. @Override
  9. public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  10. APPLICATION_CONTEXT = applicationContext;
  11. }
  12. public static ApplicationContext getApplicationContext() {
  13. return APPLICATION_CONTEXT;
  14. }
  15. }
  1. //websocket 使用service 层
  2. ApplicationContext act = ApplicationContextRegister.getApplicationContext();
  3. messagelogService=act.getBean(MessagelogService.class);
  4. int resultlog = messagelogService.insertIntoMessagelog(messagelog);

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

websocket 中使用Service层的方法的更多相关文章

  1. SpringBoot:WebSocket使用Service层的方法

    方法一: 创建工具类 ApplicationContextRegister.java import org.springframework.beans.BeansException; import o ...

  2. 【spring data jpa】使用spring data jpa时,关于service层一个方法中进行【删除】和【插入】两种操作在同一个事务内处理

    场景: 现在有这么一个情况,就是在service中提供的一个方法是先将符合条件的数据全部删除,然后再将新的条件全部插入数据库中 这个场景需要保证service中执行两步 1.删除 2.插入 这两步自然 ...

  3. 在Java filter中调用service层方法

    在项目中遇到一个问题,在 Filter中注入 Serivce失败,注入的service始终为null.如下所示: public class WeiXinFilter implements Filter ...

  4. 浅谈MVC中的service层(转)

    概述 mvc框架由model,view,controller组成,执行流程一般是:在controller访问model获取数据,通过view渲染页面. mvc模式是web开发中的基础模式,采用的是分层 ...

  5. (网页)websocket后台调用Service层

    百度论坛里面有很多好的方法,借鉴. 重点:因为项目是StringBoot所以我用的是下面的方法很好使: Service.... service = (Service....) ContextLoade ...

  6. [转]servlet中的service, doGet, doPost方法的区别和联系

    原文地址:http://m.blog.csdn.net/blog/ghyg525/22928567 大家都知道在javax.servlet.Servlet接口中只有init, service, des ...

  7. SpringBoot在自定义类中调用service层等Spring其他层

    解决方案: 1.上代码 @Component public class ServerHandler extends IoHandlerAdapter { @Autowired protected He ...

  8. Spring main方法中怎么调用Dao层和Service层的方法

    在web环境中,一般serviceImpl中的dao之类的数据库连接都由容器启动的时候创建好了,不会报错.但是在main中,没有这个环境,所以需要获取环境: ApplicationContext ct ...

  9. 事物处理service层的方法

    package cn.lijun.service; import java.sql.Connection;import java.sql.SQLException; import cn.lijun.d ...

随机推荐

  1. gitHub那些优秀的库和想要实现的效果

    1. 轮播库SDCycleScrollView 2. 自动布局库SDAutoLayout 3. 类似支付宝福卡滑动切换的效果 https://github.com/huangxuan518/HXCar ...

  2. ARGB色彩模式

    看到#ff ff ff 00 00这种 就是啦 .开头两位表示透明度.

  3. shell脚本学习 (8) fmt 格式化段落

    1 获取系统中的字典文件 -n隐藏查找过程  -e 匹配多次,只打印带p的行(不能写成-e -n) ,100p /usr/share/dict/words 会显示1-100行的字母 2 fmt 按默认 ...

  4. 4412 RS485

    一.485硬件原理 差分对传输数据的原理 IO数据的传输→差分对 rs232传输的距离在15米以下,RS485传输距离是几十米到1000米以上 为什么485可以传输这么远 差分对的机制可以降低电磁场的 ...

  5. 【Vue】记录一个之前解决跨域问题

    proxyTable: { "/proxy/": {//以/proxy/为开头的适合这个规则 target: "http://192.168.7.72:8000" ...

  6. python中chr()函数和ord()函数的用法

    一,chr()函数 格式:Chr(<数值表达式>)   说明:函数返回值类型为String,其数值表达式值取值范围为0~255.   例如:Print Chr(78),结果显示:N.   ...

  7. VB.NET导出Excel 轻松实现Excel的服务器与客户端交换 服务器不安装Office

    说来VB.Net这个也是之前的一个项目中用到的.今天拿来总结下用途,项目需求,不让在服务器安装Office办公软件.这个也是煞费了一顿. 主要的思路就是 在导出的时候,利用DataTable做中间变量 ...

  8. Hive if和coalesce函数

    链接:https://blog.csdn.net/qq_26442553/article/details/79465417 if 函数举例:

  9. Python 进阶_OOP 面向对象编程_self 的实例绑定

    目录 目录 self 和绑定 调用非绑定的方法 self 和绑定 在 Python 中 self 变量是特殊的, 其用于在实例方法中引用该方法所绑定的实例, 换句话说就是 Python 在实例化对象时 ...

  10. java继承方法覆盖

    public class TestB { private void f() { System.out.println("TestB"); } public static void ...