Example usage for org.springframework.beans.factory NoSuchBeanDefinitionException NoSuchBeanDefinitionException

List of usage examples for org.springframework.beans.factory NoSuchBeanDefinitionException NoSuchBeanDefinitionException

Introduction

In this page you can find the example usage for org.springframework.beans.factory NoSuchBeanDefinitionException NoSuchBeanDefinitionException.

Prototype

public NoSuchBeanDefinitionException(ResolvableType type) 

Source Link

Document

Create a new NoSuchBeanDefinitionException .

Usage

From source file:org.opensprout.osaf.util.ApplicationContextUtils.java

public static <T> T getBeanByType(ApplicationContext applicationContext, Class<T> clazz) {
    Map beanMap = applicationContext.getBeansOfType(clazz);
    int size = beanMap.size();
    if (size == 0) {
        if (applicationContext.getParent() != null)
            return getBeanByType(applicationContext.getParent(), clazz);
        throw new NoSuchBeanDefinitionException(clazz.getSimpleName());
    }//from w ww .  ja va2 s. c  om
    if (size > 1)
        throw new NoSuchBeanDefinitionException(
                "No unique bean definition type [" + clazz.getSimpleName() + "]");
    return (T) beanMap.values().iterator().next();
}

From source file:com.monarchapis.driver.util.SpringServiceResolverTest.java

@Before
public void setup() {
    resolver.setApplicationContext(applicationContext);

    when(applicationContext.getBean(String.class)).thenReturn("test");
    when(applicationContext.getBean(Boolean.class)).thenThrow(new NoSuchBeanDefinitionException("test"));
}

From source file:org.echocat.jomon.spring.BeanFactoryUtils.java

@Nullable
public static String findScopeOfBeanDefinition(@Nonnull ConfigurableListableBeanFactory beanFactory,
        @Nonnull String beanName) throws NoSuchBeanDefinitionException {
    final BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
    if (definition == null) {
        throw new NoSuchBeanDefinitionException("Could not find a bean named '" + beanName + "'.");
    }//  w  w w . j av a2s  .c o  m
    return definition.getScope();
}

From source file:ac.simons.spring.boot.wro4j.Wro4jAutoConfigurationTest.java

public Wro4jAutoConfigurationTest() {
    this.applicationContext = mock(ApplicationContext.class);
    when(this.applicationContext.getBean(Mockito.any(Class.class)))
            .thenThrow(new NoSuchBeanDefinitionException("foo"));
}

From source file:com.dangdang.ddframe.job.spring.schedule.SpringJobFactory.java

@Override
public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) throws SchedulerException {
    Preconditions.checkNotNull(applicationContext,
            "applicationContext cannot be null, should call setApplicationContext first.");
    Job job = null;//from   w  w w  . ja  va  2 s. c o m
    try {
        for (Job each : applicationContext.getBeansOfType(Job.class).values()) {
            if (AopUtils.getTargetClass(each) == bundle.getJobDetail().getJobClass()) {
                job = each;
                break;
            }
        }
        if (ScriptElasticJob.class == bundle.getJobDetail().getJobClass()) {
            return super.newJob(bundle, scheduler);
        }
        if (null == job) {
            throw new NoSuchBeanDefinitionException("");
        }
    } catch (final BeansException ex) {
        log.info("Elastic job: cannot found bean for class: '{}'. This job is not managed for spring.",
                bundle.getJobDetail().getJobClass().getCanonicalName());
        return super.newJob(bundle, scheduler);
    }
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.putAll(scheduler.getContext());
    jobDataMap.putAll(bundle.getJobDetail().getJobDataMap());
    jobDataMap.putAll(bundle.getTrigger().getJobDataMap());
    Job target = (Job) AopTargetUtils.getTarget(job);
    setBeanProps(target, jobDataMap);
    return target;
}

From source file:org.bigtester.ate.GlobalUtils.java

/**
 * Find test case bean./*  w w  w  .ja  va  2s.  c om*/
 *
 * @param appCtx
 *            the app ctx
 * @return the xml test case
 * @throws NoSuchBeanDefinitionException
 *             the no such bean definition exception
 */
public static TestCase findTestCaseBean(ApplicationContext appCtx) throws NoSuchBeanDefinitionException {
    Map<String, TestCase> testcases = appCtx.getBeansOfType(TestCase.class);

    if (testcases.isEmpty()) {
        throw new NoSuchBeanDefinitionException(TestCase.class);
    } else {
        TestCase retVal = testcases.values().iterator().next();
        if (null == retVal) {
            throw new NoSuchBeanDefinitionException(TestCase.class);
        } else {
            return retVal;
        }
    }
}

From source file:com.predic8.membrane.annot.parser.BlueprintSimulatedSpringApplicationContext.java

@Override
public Object getBean(String name) throws BeansException {
    try {//from w ww. j av a2 s .  c  om
        return blueprintContainer.getComponentInstance(name);
    } catch (NoSuchComponentException e) {
        throw new NoSuchBeanDefinitionException(name);
    }
}

From source file:org.horizontaldb.shard.ShardContextEnricher.java

private Object populateShardContextWithBean(ShardBean shardBean, ShardContext shardContext) {
    Object bean = getResolver(shardBean.value()).getBean(shardBean.value(), shardContext);

    if (bean == null) {
        throw new NoSuchBeanDefinitionException(shardBean.value().toString());
    }//from   ww w . java2s . com

    registerResourceWithConversation(shardContext, bean);

    shardContext.setBean(shardBean.value(), bean);

    return bean;
}

From source file:org.jboss.spring.facade.ControllerBeanFactory.java

public Object getBean(String name) throws BeansException {
    ControllerContext context = getInstalledContext(name);
    if (context == null) {
        throw new NoSuchBeanDefinitionException(name);
    }//from   ww w  .  j  av  a 2 s . c o  m

    return context.getTarget();
}

From source file:org.bigtester.ate.GlobalUtils.java

/**
 * Find step data logger bean./*from ww  w .j  a v a  2  s  .c  om*/
 *
 * @param appCtx the app ctx
 * @return the step data logger
 * @throws NoSuchBeanDefinitionException the no such bean definition exception
 */
public static StepDataLogger findStepDataLoggerBean(ApplicationContext appCtx)
        throws NoSuchBeanDefinitionException {
    Map<String, StepDataLogger> loggers = appCtx.getBeansOfType(StepDataLogger.class);

    if (loggers.isEmpty()) {
        throw new NoSuchBeanDefinitionException(TestCase.class);
    } else {
        StepDataLogger retVal = loggers.values().iterator().next();
        if (null == retVal) {
            throw new NoSuchBeanDefinitionException(TestCase.class);
        } else {
            return retVal;
        }
    }
}