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

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

Introduction

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

Prototype

@Override
    public boolean isPrototype(String name) throws NoSuchBeanDefinitionException 

Source Link

Usage

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);// ww  w  .  j  av a 2 s . c o m
            if (!prototype && !singleton) {
                return Scope.SESSION;
            }
        }
    }
    return Scope.MANAGED;
}