本文共 797 字,大约阅读时间需要 2 分钟。
首先需要一个spring静态获取bean的工具类
@Componentpublic class SpringContextBeanUtil implements ApplicationContextAware { private static ApplicationContext context; @Override public void setApplicationContext(ApplicationContext context) throws BeansException { SpringContextBeanUtil.context = context; } public staticT getBean(Class beanClass) { return context.getBean(beanClass); } public static String getMessage(String key) { return context.getMessage(key, null, Locale.getDefault()); }}
然后创建一个component 用reference注入dubbo的service
@Componentpublic class RedisComponent { @Reference(version = "1.0") private IRedisService redisService; public IRedisService getRedisService() { return redisService; }}
最后在非bean对象中调用方法获取service
转载地址:http://jpaxb.baihongyu.com/