码迷,mamicode.com
首页 > Web开发 > 详细

websocket 中使用Service层的方法

时间:2018-03-21 15:07:29      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:contex   tar   span   创建   tool   cep   override   websocket   gpo   

创建公共Utils 类    

[java] view plain copy
 
  1. ApplicationContextRegister    
[java] view plain copy
 
  1. @Component  
  2. @Lazy(false)  
  3. public class ApplicationContextRegister  implements ApplicationContextAware {  
  4.     private static ApplicationContext APPLICATION_CONTEXT;  
  5.   
  6.     /** 
  7.      * 设置spring上下文  *  * @param applicationContext spring上下文  * @throws BeansException 
  8.      */  
  9.   
  10.     @Override  
  11.     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {  
  12.         APPLICATION_CONTEXT = applicationContext;  
  13.     }  
  14.   
  15.     public static ApplicationContext getApplicationContext() {  
  16.         return APPLICATION_CONTEXT;  
  17.     }  
  18. }  

 

[java] view plain copy
 
  1. //websocket 使用service 层  
  2.               ApplicationContext act = ApplicationContextRegister.getApplicationContext();  
  3.               messagelogService=act.getBean(MessagelogService.class);  
  4.               int resultlog = messagelogService.insertIntoMessagelog(messagelog);  

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

websocket 中使用Service层的方法

标签:contex   tar   span   创建   tool   cep   override   websocket   gpo   

原文地址:https://www.cnblogs.com/duanqiao123/p/8616836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!