Search in sources :

Example 76 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-boot by spring-projects.

the class LiquibaseChangelogMissingFailureAnalyzerTests method performAnalysis.

private FailureAnalysis performAnalysis() {
    BeanCreationException failure = createFailure();
    assertThat(failure).isNotNull();
    return new LiquibaseChangelogMissingFailureAnalyzer().analyze(failure);
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException)

Example 77 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-boot by spring-projects.

the class UnboundConfigurationPropertyFailureAnalyzerTests method createFailure.

private BeanCreationException createFailure(Class<?> configuration, String... environment) {
    try {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        addEnvironment(context, environment);
        context.register(configuration);
        context.refresh();
        context.close();
        return null;
    } catch (BeanCreationException ex) {
        return ex;
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext)

Example 78 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-boot by spring-projects.

the class ConnectionFactoryBeanCreationFailureAnalyzerTests method performAnalysis.

private FailureAnalysis performAnalysis(Class<?> configuration) {
    BeanCreationException failure = createFailure(configuration);
    assertThat(failure).isNotNull();
    ConnectionFactoryBeanCreationFailureAnalyzer failureAnalyzer = new ConnectionFactoryBeanCreationFailureAnalyzer(this.environment);
    return failureAnalyzer.analyze(failure);
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException)

Example 79 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-boot by spring-projects.

the class ConnectionFactoryBeanCreationFailureAnalyzerTests method createFailure.

private BeanCreationException createFailure(Class<?> configuration) {
    try {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.setClassLoader(new FilteredClassLoader("io.r2dbc.h2", "io.r2dbc.pool"));
        context.setEnvironment(this.environment);
        context.register(configuration);
        context.refresh();
        context.close();
        return null;
    } catch (BeanCreationException ex) {
        return ex;
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader)

Example 80 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-boot by spring-projects.

the class MockitoPostProcessor method inject.

private void inject(Field field, Object target, String beanName) {
    try {
        field.setAccessible(true);
        Object existingValue = ReflectionUtils.getField(field, target);
        Object bean = this.beanFactory.getBean(beanName, field.getType());
        if (existingValue == bean) {
            return;
        }
        Assert.state(existingValue == null, () -> "The existing value '" + existingValue + "' of field '" + field + "' is not the same as the new value '" + bean + "'");
        ReflectionUtils.setField(field, target, bean);
    } catch (Throwable ex) {
        throw new BeanCreationException("Could not inject field: " + field, ex);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException)

Aggregations

BeanCreationException (org.springframework.beans.factory.BeanCreationException)133 Test (org.junit.Test)30 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)18 BeansException (org.springframework.beans.BeansException)16 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 IOException (java.io.IOException)12 Map (java.util.Map)12 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 Test (org.junit.jupiter.api.Test)11 HashMap (java.util.HashMap)9 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)9 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)8 ArrayList (java.util.ArrayList)7 PostConstruct (javax.annotation.PostConstruct)7 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)7 Bean (org.springframework.context.annotation.Bean)7 HasId (org.apache.camel.spi.HasId)6 BeanCurrentlyInCreationException (org.springframework.beans.factory.BeanCurrentlyInCreationException)6 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)6 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5