websocket 中使用Service層的方法
阿新 • • 發佈:2018-03-21
com insert int nbsp targe text into register pan
創建公共Utils 類
[java] view plain copy- 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;
- }
- }
[java] view plain copy
- //websocket 使用service 層
- ApplicationContext act = ApplicationContextRegister.getApplicationContext();
- messagelogService=act.getBean(MessagelogService.class);
- int resultlog = messagelogService.insertIntoMessagelog(messagelog);
即可使用到service裏的方法了!!
websocket 中使用Service層的方法