diff --git a/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/BeanA.java b/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/BeanA.java new file mode 100644 index 0000000000..28c39e2777 --- /dev/null +++ b/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/BeanA.java @@ -0,0 +1,5 @@ +package org.baeldung.ex.beancreationexception.cause9; + +public abstract class BeanA implements IBeanA { + // +} diff --git a/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/BeanB.java b/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/BeanB.java new file mode 100644 index 0000000000..d012dc6a0b --- /dev/null +++ b/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/BeanB.java @@ -0,0 +1,8 @@ +package org.baeldung.ex.beancreationexception.cause9; + +import org.springframework.stereotype.Component; + +@Component +public class BeanB { + // +} \ No newline at end of file diff --git a/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/IBeanA.java b/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/IBeanA.java new file mode 100644 index 0000000000..82114b18da --- /dev/null +++ b/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/cause9/IBeanA.java @@ -0,0 +1,5 @@ +package org.baeldung.ex.beancreationexception.cause9; + +public interface IBeanA { + // +} diff --git a/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/spring/Cause9ContextWithJavaConfig.java b/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/spring/Cause9ContextWithJavaConfig.java new file mode 100644 index 0000000000..d64ec9ab3d --- /dev/null +++ b/spring-exceptions/src/main/java/org/baeldung/ex/beancreationexception/spring/Cause9ContextWithJavaConfig.java @@ -0,0 +1,30 @@ +package org.baeldung.ex.beancreationexception.spring; + +import org.baeldung.ex.beancreationexception.cause9.BeanB; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@ComponentScan("org.baeldung.ex.beancreationexception.cause9") +@ImportResource("classpath:beancreationexception_cause9.xml") +public class Cause9ContextWithJavaConfig { + @Autowired + BeanFactory beanFactory; + + public Cause9ContextWithJavaConfig() { + super(); + } + + // beans + + @Bean + public BeanB beanB() { + beanFactory.getBean("beanA"); + return new BeanB(); + } + +} \ No newline at end of file diff --git a/spring-exceptions/src/main/resources/beancreationexception_cause9.xml b/spring-exceptions/src/main/resources/beancreationexception_cause9.xml new file mode 100644 index 0000000000..74878a62da --- /dev/null +++ b/spring-exceptions/src/main/resources/beancreationexception_cause9.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/spring-exceptions/src/test/java/org/baeldung/ex/beancreationexception/Cause9BeanCreationExceptionIntegrationTest.java b/spring-exceptions/src/test/java/org/baeldung/ex/beancreationexception/Cause9BeanCreationExceptionIntegrationTest.java new file mode 100644 index 0000000000..ad1ba5f2f1 --- /dev/null +++ b/spring-exceptions/src/test/java/org/baeldung/ex/beancreationexception/Cause9BeanCreationExceptionIntegrationTest.java @@ -0,0 +1,19 @@ +package org.baeldung.ex.beancreationexception; + +import org.baeldung.ex.beancreationexception.spring.Cause9ContextWithJavaConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { Cause9ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class) +public class Cause9BeanCreationExceptionIntegrationTest { + + @Test + public final void givenContextIsInitialized_thenNoException() { + // + } + +}