java注解 remote_spring扫描自定义注解并进行操作

转载:http://blog.csdn.net/cuixuefeng1112/article/details/45331233

/**

* 扫描注解添加服务到缓存以供判断时候为对外开放service

*/

@Component

@Lazy(true)

class AnnotationScannerConfigurer implements BeanDefinitionRegistryPostProcessor {

ArrayList cache=RemoteCache.getCache();

@Override

public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {

}

@Override

public void postProcessBeanFactory(ConfigurableListableBeanFactory postProcessBeanFactory) throws BeansException {

Map map=configurableListableBeanFactory.getBeansWithAnnotation(RemoteTag.class);

for (String key : map.keySet()) {

cache.add(key);

//System.out.println("beanName= "+ key );

}

}

}

我的AnnotationScannerConfigurer  实现了BeanDefinitionRegistryPostProcessor

,spring启动时会执行postProcessBeanFactory方法,通过postProcessBeanFactory我们就可以拿到@RemoteTag所修饰的bean了。然后随你怎么操作。

使用BeanDefinitionRegistryPostProcessor 是从mybaties的spring扫描实现类得到灵感的。

注意:@Lazy(true)是因为最后加载才能确保把所有@RemoteTag修饰的bean得到并进行操作。

SpringBoot:已经找到方法了。我用的是类继承ApplicationListener

然后用event.getApplicationContext().getBeansWithAnnotation(TableBind.class);即可

多谢大家

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值