本文整理了Java中org.springframework.context.ApplicationContext.getBeansWithAnnotation()
方法的一些代码示例,展示了ApplicationContext.getBeansWithAnnotation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.getBeansWithAnnotation()
方法的具体详情如下:
包路径:org.springframework.context.ApplicationContext
类名称:ApplicationContext
方法名:getBeansWithAnnotation
暂无
代码示例来源:origin: spring-projects/spring-security
@Override
public void init(AuthenticationManagerBuilder auth) {
Map<String, Object> beansWithAnnotation = context
.getBeansWithAnnotation(EnableGlobalAuthentication.class);
if (logger.isDebugEnabled()) {
logger.debug("Eagerly initializing " + beansWithAnnotation);
}
}
}
代码示例来源:origin: alibaba/dubbo-spring-boot-starter
@PostConstruct
public void init() throws Exception {
Map<String, Object> beanMap = this.applicationContext.getBeansWithAnnotation(Service.class);
if (beanMap != null && beanMap.size() > 0) {
this.initIdConfigMap(this.properties);
for (Map.Entry<String, Object> entry : beanMap.entrySet()) {
this.initProviderBean(entry.getKey(), entry.getValue());
}
}
}
代码示例来源:origin: shuzheng/zheng
LOGGER.debug(">>>>> spring初始化完毕 <<<<<");
Map<String, Object> baseServices = contextRefreshedEvent.getApplicationContext().getBeansWithAnnotation(BaseService.class);
for(Object service : baseServices.values()) {
LOGGER.debug(">>>>> {}.initMapper()", service.getClass().getName());
代码示例来源:origin: luxiaoxun/NettyRpc
@Override
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
Map<String, Object> serviceBeanMap = ctx.getBeansWithAnnotation(RpcService.class);
if (MapUtils.isNotEmpty(serviceBeanMap)) {
for (Object serviceBean : serviceBeanMap.values()) {
String interfaceName = serviceBean.getClass().getAnnotation(RpcService.class).value().getName();
logger.info("Loading service: {}", interfaceName);
handlerMap.put(interfaceName, serviceBean);
}
}
}
代码示例来源:origin: aol/micro-server
public LinkedListX getRestResources(ApplicationContext rootContext){
List resources = new ArrayList<>();
module.getRestResourceClasses().forEach(it -> resources.addAll(rootContext.getBeansOfType(it).values()));
module.getRestAnnotationClasses().forEach(it -> resources.addAll(rootContext.getBeansWithAnnotation(it).values()));
rootContext.getBeansWithAnnotation(JaxRsResource.class).forEach((n,it)->resources.add(it));
rootContext.getBeansOfType(JaxRsResourceWrapper.class).forEach((n,it)->resources.add(it.getResource()));
resources.addAll(module.getJaxRsResourceObjects());
return LinkedListX.fromIterable(resources);
}
代码示例来源:origin: xuxueli/xxl-job
private void initJobHandlerRepository(ApplicationContext applicationContext){
if (applicationContext == null) {
return;
}
// init job handler action
Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHandler.class);
if (serviceBeanMap!=null && serviceBeanMap.size()>0) {
for (Object serviceBean : serviceBeanMap.values()) {
if (serviceBean instanceof IJobHandler){
String name = serviceBean.getClass().getAnnotation(JobHandler.class).value();
IJobHandler handler = (IJobHandler) serviceBean;
if (loadJobHandler(name) != null) {
throw new RuntimeException("xxl-job jobhandler naming conflicts.");
}
registJobHandler(name, handler);
}
}
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
@Override
protected void initJobNode() {
jobClient = JobClientBuilder.buildByProperties(properties);
Map<String, Object> handlers = applicationContext.getBeansWithAnnotation(JobCompletedHandler4JobClient.class);
if (CollectionUtils.isNotEmpty(handlers)) {
if (handlers.size() > 1) {
throw new IllegalArgumentException("annotation @" + JobCompletedHandler4JobClient.class.getSimpleName() + " only should have one");
}
for (Map.Entry<String, Object> entry : handlers.entrySet()) {
Object handler = entry.getValue();
if (handler instanceof JobCompletedHandler) {
jobClient.setJobCompletedHandler((JobCompletedHandler) entry.getValue());
} else {
throw new IllegalArgumentException(entry.getKey() + " is not instance of " + JobCompletedHandler.class.getName());
}
}
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
@Override
protected void initJobNode() {
jobClient = JobClientBuilder.buildByProperties(properties);
Map<String, Object> handlers = applicationContext.getBeansWithAnnotation(JobCompletedHandler4JobClient.class);
if (CollectionUtils.isNotEmpty(handlers)) {
if (handlers.size() > 1) {
throw new IllegalArgumentException("annotation @" + JobCompletedHandler4JobClient.class.getSimpleName() + " only should have one");
}
for (Map.Entry<String, Object> entry : handlers.entrySet()) {
Object handler = entry.getValue();
if (handler instanceof JobCompletedHandler) {
jobClient.setJobCompletedHandler((JobCompletedHandler) entry.getValue());
} else {
throw new IllegalArgumentException(entry.getKey() + " is not instance of " + JobCompletedHandler.class.getName());
}
}
}
}
代码示例来源:origin: linlinjava/litemall
public static Map<RequiresPermissions, RequiresPermissionsDesc> findPermissions(ApplicationContext context, String basicPackage) {
Map<String, Object> map = context.getBeansWithAnnotation(Controller.class);
Map<RequiresPermissions, RequiresPermissionsDesc> permissions = new HashMap<>();
for(Map.Entry<String, Object> entry : map.entrySet()){
Object bean = entry.getValue();
if(!StringUtils.contains(ClassUtils.getPackageName(bean.getClass()), basicPackage)){
continue;
}
Class<?> clz = bean.getClass();
Class controllerClz = clz.getSuperclass();
List<Method> methods = MethodUtils.getMethodsListWithAnnotation(controllerClz, RequiresPermissions.class);
for(Method method : methods){
RequiresPermissions requiresPermissions = AnnotationUtils.getAnnotation(method, RequiresPermissions.class);
RequiresPermissionsDesc requiresPermissionsDesc = AnnotationUtils.getAnnotation(method, RequiresPermissionsDesc.class);
if(requiresPermissions == null || requiresPermissionsDesc == null){
continue;
}
permissions.put(requiresPermissions, requiresPermissionsDesc);
}
}
return permissions;
}
代码示例来源:origin: ltsopensource/light-task-scheduler
Map<String, Object> jobRunners = applicationContext.getBeansWithAnnotation(JobRunner4TaskTracker.class);
if (CollectionUtils.isNotEmpty(jobRunners)) {
if (jobRunners.size() > 1) {
Map<String, Object> ltsBeanMap = applicationContext.getBeansWithAnnotation(LTS.class);
if (CollectionUtils.isNotEmpty(ltsBeanMap)) {
for (Map.Entry<String, Object> entry : ltsBeanMap.entrySet()) {
代码示例来源:origin: ltsopensource/light-task-scheduler
Map<String, Object> jobRunners = applicationContext.getBeansWithAnnotation(JobRunner4TaskTracker.class);
if (CollectionUtils.isNotEmpty(jobRunners)) {
if (jobRunners.size() > 1) {
Map<String, Object> ltsBeanMap = applicationContext.getBeansWithAnnotation(LTS.class);
if (CollectionUtils.isNotEmpty(ltsBeanMap)) {
for (Map.Entry<String, Object> entry : ltsBeanMap.entrySet()) {
代码示例来源:origin: ltsopensource/light-task-scheduler
private void injectMasterChangeListeners() {
Map<String, Object> listeners = applicationContext.getBeansWithAnnotation(MasterNodeListener.class);
if (CollectionUtils.isNotEmpty(listeners)) {
for (Map.Entry<String, Object> entry : listeners.entrySet()) {
Object listener = entry.getValue();
MasterNodeListener annotation = listener.getClass().getAnnotation(MasterNodeListener.class);
NodeType[] nodeTypes = annotation.nodeTypes();
boolean ok = false;
if (nodeTypes != null && nodeTypes.length > 0) {
for (NodeType type : nodeTypes) {
if (type == nodeType()) {
ok = true;
break;
}
}
} else {
ok = true;
}
if (!ok) {
continue;
}
if (listener instanceof MasterChangeListener) {
getJobNode().addMasterChangeListener((MasterChangeListener) listener);
} else {
LOGGER.warn(entry.getKey() + " is not instance of " + MasterChangeListener.class.getName());
}
}
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
private void injectMasterChangeListeners() {
Map<String, Object> listeners = applicationContext.getBeansWithAnnotation(MasterNodeListener.class);
if (CollectionUtils.isNotEmpty(listeners)) {
for (Map.Entry<String, Object> entry : listeners.entrySet()) {
Object listener = entry.getValue();
MasterNodeListener annotation = listener.getClass().getAnnotation(MasterNodeListener.class);
NodeType[] nodeTypes = annotation.nodeTypes();
boolean ok = false;
if (nodeTypes != null && nodeTypes.length > 0) {
for (NodeType type : nodeTypes) {
if (type == nodeType()) {
ok = true;
break;
}
}
} else {
ok = true;
}
if (!ok) {
continue;
}
if (listener instanceof MasterChangeListener) {
getJobNode().addMasterChangeListener((MasterChangeListener) listener);
} else {
LOGGER.warn(entry.getKey() + " is not instance of " + MasterChangeListener.class.getName());
}
}
}
}
代码示例来源:origin: org.springframework.security/spring-security-config
@Override
public void init(AuthenticationManagerBuilder auth) {
Map<String, Object> beansWithAnnotation = context
.getBeansWithAnnotation(EnableGlobalAuthentication.class);
if (logger.isDebugEnabled()) {
logger.debug("Eagerly initializing " + beansWithAnnotation);
}
}
}
代码示例来源:origin: youseries/urule
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
resourceBuilders=applicationContext.getBeansOfType(ResourceBuilder.class).values();
providers=applicationContext.getBeansOfType(ResourceProvider.class).values();
this.applicationContext=applicationContext;
applicationContext.getBeansWithAnnotation(SuppressWarnings.class);
}
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
private Map<String, Object> getConfigurationPropertiesBeans(
ApplicationContext context,
ConfigurationBeanFactoryMetadata beanFactoryMetadata) {
Map<String, Object> beans = new HashMap<>();
beans.putAll(context.getBeansWithAnnotation(ConfigurationProperties.class));
if (beanFactoryMetadata != null) {
beans.putAll(beanFactoryMetadata
.getBeansWithFactoryAnnotation(ConfigurationProperties.class));
}
return beans;
}
代码示例来源:origin: alibaba/asyncload
@Override
public void afterPropertiesSet() throws Exception {
Map<String, Object> asyncLoadBeanMap = applicationContext
.getBeansWithAnnotation(AsyncClassDef.class);
// 遍历对应的对象填充对应的map
for (Object beanObj : asyncLoadBeanMap.values()) {
// 因为被拦截器拦住,使用cglib进行代理,所有需要获得对应的原始类
Class<?> originBeanClass = AopProxyUtils.ultimateTargetClass(beanObj);
// 解析类上面的注解
AsyncLoadExecutor asyncLoadExecutor = parseClassAnnotation(originBeanClass);
// 解析方法上面的注解
parseMethodAnnotation(originBeanClass, asyncLoadExecutor);
}
LOGGER.info(MessageFormat.format(
"异步并行加载解析对应的结果methodAsyncTemplateTable={0},methodConfExecMap={1}",
methodAsyncTemplateTable, methodConfExecMap));
}
代码示例来源:origin: com.graphaware.neo4j/server
@Autowired
public ControllerStatsCollector(StatsCollector statsCollector, ApplicationContext context) {
for (Object bean : context.getBeansWithAnnotation(Controller.class).values()) {
statsCollector.moduleStart(bean.getClass().getCanonicalName());
}
}
}
代码示例来源:origin: apache/archiva
@Override
public Map<String, Object> getBeansWithAnnotation( Class<? extends Annotation> aClass )
throws BeansException
{
return applicationContext.getBeansWithAnnotation( aClass );
}
代码示例来源:origin: top.wboost/common-web
@Override
public void onRootApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
Map<String, Object> servicess = context.getBeansWithAnnotation(Service.class);
servicess.forEach((name, bean) -> {
Object target = AopUtils.getTarget(bean);
if (ClassUtils.isAssignable(top.wboost.common.base.old.service.impl.BaseJpaServiceImpl.class,
target.getClass())) {
autowired((BaseJpaServiceImpl) target);
}
});
}
内容来源于网络,如有侵权,请联系作者删除!