bean examples
This commit is contained in:
parent
ac29c2e553
commit
bdc54a57b1
14
spring-all/src/main/java/org/baeldung/di/core/BeanA.java
Normal file
14
spring-all/src/main/java/org/baeldung/di/core/BeanA.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package org.baeldung.di.core;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class BeanA {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("beanB2")
|
||||||
|
private IBeanB dependency;
|
||||||
|
|
||||||
|
}
|
8
spring-all/src/main/java/org/baeldung/di/core/BeanB.java
Normal file
8
spring-all/src/main/java/org/baeldung/di/core/BeanB.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package org.baeldung.di.core;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class BeanB implements IBeanB {
|
||||||
|
//
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package org.baeldung.di.core;
|
||||||
|
|
||||||
|
public interface IBeanB {
|
||||||
|
//
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.baeldung.di.core;
|
||||||
|
|
||||||
|
import org.baeldung.di.spring.ContextWithJavaConfig;
|
||||||
|
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 = { ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||||
|
public class DependencyInjectionWithJavaIntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenContextIsInitialized_thenNoException() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user