标签:applicationContext YmsSessionMangager return spring YmsSessionMangagerYhtApp jar
场景:sdk 里获取spring 的bean
1、先新建一个类
1 package com.yonyou.yht.bean; 2 3 import com.yonyou.iuap.yms.session.YmsSessionMangager; 4 import org.springframework.beans.BeansException; 5 import org.springframework.context.ApplicationContext; 6 import org.springframework.context.ApplicationContextAware; 7 8 public class YmsSessionMangagerYhtApp implements ApplicationContextAware { 9 10 private static ApplicationContext applicationContext; 11 12 @Override 13 public synchronized void setApplicationContext(ApplicationContext applicationContext) 14 throws BeansException { 15 YmsSessionMangagerYhtApp.applicationContext = applicationContext; 16 } 17 18 public static YmsSessionMangager getYmsSessionMangagerBean() { 19 if (applicationContext == null) { 20 return null; 21 } 22 return applicationContext.getBean(YmsSessionMangager.class); 23 } 24 }
2、SDK里调用的时候
private static Map<String, String> getSession2RemoteStorage(String token) { try { YmsSessionMangager bean = YmsSessionMangagerYhtApp.getYmsSessionMangagerBean(); if (bean == null) { return null; } return bean.getSession2RemoteStorage(token); } catch (Exception e) { logger.error("UserCenter saveSession2Storage error, [msg = {}]", e.getMessage(), e); return null; } }
3、项目里调用的时候,需要注入这个bean
@Bean("ymsSessionMangagerYhtApp") public YmsSessionMangagerYhtApp ymsSessionMangagerYhtApp() { return new YmsSessionMangagerYhtApp(); }
原创文章,欢迎转载,转载请注明出处!
标签:applicationContext,YmsSessionMangager,return,spring,YmsSessionMangagerYhtApp,jar 来源: https://www.cnblogs.com/acm-bingzi/p/jar_spring_bean.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。