Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext getBeansOfType

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getBeansOfType

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigApplicationContext getBeansOfType.

Prototype

@Override
    public <T> Map<String, T> getBeansOfType(@Nullable Class<T> type) throws BeansException 

Source Link

Usage

From source file:playground.app.Application.java

public static HttpHandler createHttpHandler() throws IOException {
    Properties prop = new Properties();
    prop.load(Application.class.getClassLoader().getResourceAsStream("application.properties"));
    String profiles = prop.getProperty("profiles");
    if (profiles != null) {
        System.setProperty("spring.profiles.active", profiles);
    }//from  w w w  .jav a 2s  .  co m

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("playground");

    DispatcherHandler dispatcherHandler = new DispatcherHandler();
    dispatcherHandler.setApplicationContext(context);

    Map<String, WebFilter> beanNameToFilters = context.getBeansOfType(WebFilter.class);
    WebFilter[] filters = beanNameToFilters.values().toArray(new WebFilter[0]);
    Arrays.sort(filters, AnnotationAwareOrderComparator.INSTANCE);

    return WebHttpHandlerBuilder.webHandler(dispatcherHandler)
            .exceptionHandlers(new ResponseStatusExceptionHandler()).filters(filters).build();
}

From source file:org.ocelotds.spring.SpringResolver.java

@Override
public Scope getScope(Class clazz) {
    logger.debug("Try to get scope of class {}", clazz);
    AnnotationConfigApplicationContext applicationCtx = this.getApplicationContext();
    Map<String, ?> beansOfType = applicationCtx.getBeansOfType(clazz);
    if (beansOfType != null) {
        logger.debug("Try to get scope of class {} from beans", clazz);
        String bean = beansOfType.keySet().iterator().next();
        logger.debug("Try to get scope of class {} from bean {}", clazz, bean);
        if (bean != null) {
            boolean prototype = applicationCtx.isPrototype(bean);
            boolean singleton = applicationCtx.isSingleton(bean);
            logger.debug("Try to get scope of class {} prototype : {}, singleton : {}", clazz, prototype,
                    singleton);//from  w w w . ja  va  2  s .  c o m
            if (!prototype && !singleton) {
                return Scope.SESSION;
            }
        }
    }
    return Scope.MANAGED;
}

From source file:com.khartec.waltz.web.Main.java

public void start(ServerMode mode) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    Map<String, Endpoint> endpoints = ctx.getBeansOfType(Endpoint.class);
    endpoints.forEach((name, endpoint) -> {
        LOG.info("Registering Endpoint: {}", name);
        endpoint.register();// www  .j  av a 2s  .c o  m
    });

    new StaticResourcesEndpoint().register();

    LOG.info("Completed endpoint registration");

    registerExceptionHandlers();
    // enableGZIP();
    enableCORS();

}