Java Code Examples for org.springframework.context.ApplicationContext.getBeansWithAnnotation()

The following are Jave code examples for showing how to use getBeansWithAnnotation() of the org.springframework.context.ApplicationContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lemon   File: RestFilter.java   View Source Code Vote up 6 votes
public void doFilter(ServletRequest req, ServletResponse res,
        FilterChain filterChain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    ApplicationContext ctx = ApplicationContextHelper
            .getApplicationContext();
    Map<String, Object> map = ctx.getBeansWithAnnotation(Path.class);

    for (Object object : map.values()) {
        Class clz = object.getClass();

        for (Method method : clz.getDeclaredMethods()) {
            if (this.matches(request, method)) {
                Map<String, String> parameters = parseBody(request
                        .getInputStream());
                this.invokeMethod(request, response, object, method,
                        parameters);

                return;
            }
        }
    }

    filterChain.doFilter(req, res);
}
 
Example 2
Project: stage-job   File: XxlJobExecutor.java   View Source Code Vote up 6 votes
private static void initJobHandlerRepository(ApplicationContext applicationContext){
    // 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);
            }
        }
    }
}
 
Example 3
Project: xxl-job   File: XxlJobExecutor.java   View Source Code Vote up 6 votes
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
       XxlJobExecutor.applicationContext = applicationContext;

       // init job handler action
       Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHander.class);

       if (serviceBeanMap!=null && serviceBeanMap.size()>0) {
           for (Object serviceBean : serviceBeanMap.values()) {
               if (serviceBean instanceof IJobHandler){
                   String name = serviceBean.getClass().getAnnotation(JobHander.class).value();
                   IJobHandler handler = (IJobHandler) serviceBean;
                   registJobHandler(name, handler);
               }
           }
       }
}
 
Example 4
Project: lionrpc   File: LionServer.java   View Source Code Vote up 5 votes
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    Map<String,Object> lionServiceMap = applicationContext.getBeansWithAnnotation(LionService.class);
    if(lionServiceMap != null){
        for (Object serviceBean : lionServiceMap.values()) {
            String interfaceName = serviceBean.getClass().getAnnotation(LionService.class).value().getName();
            serverHandlerMap.put(interfaceName, serviceBean);
        }
    }
}
 
Example 5
Project: buddha   File: RpcServer.java   View Source Code Vote up 5 votes
public void setApplicationContext(ApplicationContext applicationContext)
        throws BeansException {
    Map<String, Object> serviceMap = applicationContext.getBeansWithAnnotation(RpcService.class);
    if (MapUtils.isNotEmpty(serviceMap)) {
        for (Object bean : serviceMap.values()) {
            String interfaceName = bean.getClass().getAnnotation(RpcService.class).value().getName();
            handlerMap.put(interfaceName, bean);
        }
    }
}
 
Example 6
Project: alfresco-remote-api   File: ApiBootstrap.java   View Source Code Vote up 5 votes
@Override
protected void onBootstrap(ApplicationEvent event)
{
    logger.info("Bootstapping the API");
    ContextRefreshedEvent refreshEvent = (ContextRefreshedEvent)event;
    ApplicationContext ac = refreshEvent.getApplicationContext();
    Map<String, Object> entityResourceBeans = ac.getBeansWithAnnotation(EntityResource.class);
    Map<String, Object> relationResourceBeans = ac.getBeansWithAnnotation(RelationshipResource.class);
    apiDictionary.setDictionary(ResourceDictionaryBuilder.build(entityResourceBeans.values(), relationResourceBeans.values()));
}
 
Example 7
Project: urule   File: AbstractBuilder.java   View Source Code Vote up 4 votes
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);
}
 
Example 8
Project: cstruct-parser   File: AbstractDispatchCenterService.java   View Source Code Vote up 4 votes
public void refresh(ApplicationContext applicationContext)
{
	handleMessageServiceMapping = new HashMap<String, HandleMessageService>();

	Map<String, Object> beans = applicationContext.getBeansWithAnnotation(HandleMessageProtocol.class);

	for (Object bean : beans.values()) {

		if (!(bean instanceof HandleMessageService)) {
			continue;
		}

		HandleMessageProtocol tmp = null;

		tmp = bean.getClass().getAnnotation(HandleMessageProtocol.class);

		addHandleMessageService(tmp.id(), (HandleMessageService) bean);

	}
}
 
Example 9
Project: spring-boot-starter-converter   File: ConverterStartListener.java   View Source Code Vote up 4 votes
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
    ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
    Map<String, Object> converterBeans = applicationContext.getBeansWithAnnotation(Converter.class);
    ConverterContext.initialize(converterProperties, converterBeans);
}