exception work
This commit is contained in:
parent
bdc54a57b1
commit
843c33616a
@ -1,5 +0,0 @@
|
|||||||
package org.baeldung.di.core;
|
|
||||||
|
|
||||||
public interface IBeanB {
|
|
||||||
//
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package org.baeldung.di.spring;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan("org.baeldung.di")
|
|
||||||
public class ContextWithJavaConfig {
|
|
||||||
|
|
||||||
public ContextWithJavaConfig() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
// beans
|
|
||||||
|
|
||||||
}
|
|
@ -1,14 +1,12 @@
|
|||||||
package org.baeldung.di.core;
|
package org.baeldung.ex.nosuchbeandefinitionexception.cause1;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class BeanA {
|
public class BeanA {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("beanB2")
|
private BeanB dependency;
|
||||||
private IBeanB dependency;
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package org.baeldung.ex.nosuchbeandefinitionexception.cause1;
|
||||||
|
|
||||||
|
public class BeanB {
|
||||||
|
//
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.baeldung.ex.nosuchbeandefinitionexception.cause3;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class BeanA implements InitializingBean {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationContext context;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void afterPropertiesSet() {
|
||||||
|
context.getBean("test");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.baeldung.di.core;
|
package org.baeldung.ex.nosuchbeandefinitionexception.cause3;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -0,0 +1,5 @@
|
|||||||
|
package org.baeldung.ex.nosuchbeandefinitionexception.cause3;
|
||||||
|
|
||||||
|
public interface IBeanB {
|
||||||
|
//
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.baeldung.ex.nosuchbeandefinitionexception.spring;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan("org.baeldung.di.cause1")
|
||||||
|
public class Cause1ContextWithJavaConfig {
|
||||||
|
|
||||||
|
public Cause1ContextWithJavaConfig() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
// beans
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.baeldung.ex.nosuchbeandefinitionexception.spring;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan("org.baeldung.di.cause2")
|
||||||
|
public class Cause2ContextWithJavaConfig {
|
||||||
|
|
||||||
|
public Cause2ContextWithJavaConfig() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
// beans
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.baeldung.ex.nosuchbeandefinitionexception.spring;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan("org.baeldung.di.cause2")
|
||||||
|
public class Cause3ContextWithJavaConfig {
|
||||||
|
|
||||||
|
public Cause3ContextWithJavaConfig() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
// beans
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package org.baeldung.di.core;
|
package org.baeldung.ex.nosuchbeandefinitionexception;
|
||||||
|
|
||||||
import org.baeldung.di.spring.ContextWithJavaConfig;
|
import org.baeldung.ex.nosuchbeandefinitionexception.spring.Cause1ContextWithJavaConfig;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
@ -8,8 +8,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
@ContextConfiguration(classes = { Cause1ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||||
public class DependencyInjectionWithJavaIntegrationTest {
|
public class Cause1NoSuchBeanDefinitionExceptionIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void givenContextIsInitialized_thenNoException() {
|
public final void givenContextIsInitialized_thenNoException() {
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.baeldung.ex.nosuchbeandefinitionexception;
|
||||||
|
|
||||||
|
import org.baeldung.ex.nosuchbeandefinitionexception.spring.Cause2ContextWithJavaConfig;
|
||||||
|
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 = { Cause2ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||||
|
public class Cause2NoSuchBeanDefinitionExceptionIntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenContextIsInitialized_thenNoException() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.baeldung.ex.nosuchbeandefinitionexception;
|
||||||
|
|
||||||
|
import org.baeldung.ex.nosuchbeandefinitionexception.spring.Cause3ContextWithJavaConfig;
|
||||||
|
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 = { Cause3ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||||
|
public class Cause3NoSuchBeanDefinitionExceptionIntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenContextIsInitialized_thenNoException() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user