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 ...
随机推荐
- C# json对象中包含数组对象时,如何存入数据库
前端创建的的对象例如: C#端这样将数组提取出来存入
- 【leetcode】714. Best Time to Buy and Sell Stock with Transaction Fee
题目如下: Your are given an array of integers prices, for which the i-th element is the price of a given ...
- 【Java】java获取request body
//方式一 public static String ReadAsChars(HttpServletRequest request) { BufferedReader br = null; Strin ...
- 多任务Multitask Learning
一次只学习一个任务,大部分机器学习都属于单任务学习. 多任务学习:把多个相关的任务放在一起学习,同时学习多个任务. 对于复杂的问题,可以分解为简单的相互独立的子问题来解决,然后再合并结果,得到最初复杂 ...
- C#读取csv、xls、sql数据库的实现
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- Linux 下查看操作系统信息
1.uname -a 可显示电脑以及操作系统的相关信息. 2.输入"cat /proc/version",说明正在运行的内核版本. 3.输入"cat /etc/issu ...
- gradle 国内加速,修改镜像源
为什么慢 由于默认情况下执行 gradle 各种命令是去国外的 gradle 官方镜像源获取需要安装的具体软件信息,所以在不使用代理.不翻墙的情况下,从国内访问国外服务器的速度相对比较慢 如何修改镜像 ...
- frida的js脚本处理正则的一个小坑
frida的server模式需要python支持,所以js脚本中的正则需要多一次转义 比如匹配"/proc/{数字pid}" server: paramPath.match(&qu ...
- 通过注册表修改IE的Internet选项
Internet Explorer 安全区域设置存储在以下注册表子项下面: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\I ...
- 把 MongoDB 当成是纯内存数据库来使用(Redis 风格)
基本思想 将MongoDB用作内存数据库(in-memory database),也即,根本就不让MongoDB把数据保存到磁盘中的这种用法,引起了越来越多的人的兴趣.这种用法对于以下应用场合来讲,超 ...