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

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

Introduction

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

Prototype

@Nullable
public Class<?> getBeanType() 

Source Link

Document

Return the required type of the missing bean, if it was a lookup by type that failed.

Usage

From source file:com.moisespsena.vraptor.resourceexec.ResourceMethodExecution.java

public MethodInfo execute(final RequestMethodInfo requestMethodInfo) {
    RequestMethodInfoStatic.hydatesRequest(servletRequest, requestMethodInfo);
    ResourceMethodExecutionStatic.mark(servletRequest);
    // clear methodInfo result
    methodInfo.setResult(null);//from ww  w. j ava  2  s.  c  o m
    // informa que ResourceExec sera utilizado
    resourceExecResult.setUsing(true);

    try {
        stackExecution.execute();

        if (validator.hasErrors()) {
            requestResult = RequestResultImpl
                    .preConditionFailed(new CategorizedMessagesImpl(flashMessages.getMessages()));
        } else {
            resourceExecResult.dispatchPreResultGenerateListeners();

            final ResourceMethodResult resourceMethodResult = new ResourceMethodResultImpl(
                    methodInfo.getResult());
            requestResult = RequestResultImpl.result(resourceMethodResult,
                    new CategorizedMessagesImpl(flashMessages.getMessages()));
        }
    } catch (final NoSuchBeanDefinitionException e) {
        if (e.getBeanType().equals(requestMethodInfo.getResourceClass())) {
            requestResult = RequestResultImpl.notFound();
        } else {
            throw e;
        }
    } finally {
        ResourceMethodExecutionStatic.unmark(servletRequest);
        RequestMethodInfoStatic.dehydatesRequest(servletRequest);
        resourceExecResult.generated();
    }

    return methodInfo;
}

From source file:com.solace.spring.boot.autoconfigure.SolaceJavaAutoCloudConfigurationTest.java

@Test(expected = NoSuchBeanDefinitionException.class)
public void noBeanNotCloud() throws NoSuchBeanDefinitionException {
    load("");//ww w .  j a v  a2s. co m
    try {
        this.context.getBean(beanClass);
    } catch (NoSuchBeanDefinitionException e) {
        assertTrue(e.getBeanType().isAssignableFrom(beanClass));
        throw e;
    }
}

From source file:com.solace.spring.boot.autoconfigure.SolaceJavaAutoCloudConfigurationTest.java

@Test(expected = NoSuchBeanDefinitionException.class)
public void noBeanIsCloudNoService() throws NoSuchBeanDefinitionException {
    load(CF_CLOUD_APP_ENV);/*from w ww  . j a  v a2  s. c  o m*/

    Environment env = context.getEnvironment();
    String VCAP_APPLICATION = env.getProperty("VCAP_APPLICATION");
    assertNotNull(VCAP_APPLICATION);
    assertEquals("{}", VCAP_APPLICATION);

    String VCAP_SERVICES = env.getProperty("VCAP_SERVICES");
    assertNull(VCAP_SERVICES);

    try {
        this.context.getBean(beanClass);
    } catch (NoSuchBeanDefinitionException e) {
        assertTrue(e.getBeanType().isAssignableFrom(beanClass));
        throw e;
    }
}

From source file:com.solace.spring.boot.autoconfigure.SolaceJavaAutoCloudConfigurationTest.java

@Test(expected = NoSuchBeanDefinitionException.class)
public void noBeanIsCloudWrongService() throws NoSuchBeanDefinitionException {
    load(CF_CLOUD_APP_ENV, CF_VCAP_SERVICES_OTHER);

    Environment env = context.getEnvironment();
    String VCAP_APPLICATION = env.getProperty("VCAP_APPLICATION");
    assertNotNull(VCAP_APPLICATION);//w w w. j  a  va 2 s .  c o m
    assertEquals("{}", VCAP_APPLICATION);

    String VCAP_SERVICES = env.getProperty("VCAP_SERVICES");
    assertNotNull(VCAP_SERVICES);
    assertFalse(VCAP_SERVICES.contains("solace-messaging"));

    try {
        this.context.getBean(beanClass);
    } catch (NoSuchBeanDefinitionException e) {
        assertTrue(e.getBeanType().isAssignableFrom(beanClass));
        throw e;
    }
}

From source file:org.archive.crawler.framework.CrawlJob.java

/**
 * Return a short useful message for common BeansExceptions. 
 * @param ex BeansException/*from  w w  w  .j  ava 2  s  .co m*/
 * @return String short descriptive message
 */
protected String shortMessage(BeansException ex) {
    if (ex instanceof NoSuchBeanDefinitionException) {
        NoSuchBeanDefinitionException nsbde = (NoSuchBeanDefinitionException) ex;
        return "Missing required bean: "
                + (nsbde.getBeanName() != null ? "\"" + nsbde.getBeanName() + "\" " : "")
                + (nsbde.getBeanType() != null ? "\"" + nsbde.getBeanType() + "\" " : "");
    }
    if (ex instanceof BeanCreationException) {
        BeanCreationException bce = (BeanCreationException) ex;
        return bce.getBeanName() == null ? "" : "Can't create bean '" + bce.getBeanName() + "'";
    }
    return ex.getMessage().replace('\n', ' ');
}