bean examples

This commit is contained in:
eugenp 2013-07-05 01:44:43 +03:00
parent ac29c2e553
commit bdc54a57b1
5 changed files with 62 additions and 0 deletions

View 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;
}

View File

@ -0,0 +1,8 @@
package org.baeldung.di.core;
import org.springframework.stereotype.Component;
@Component
public class BeanB implements IBeanB {
//
}

View File

@ -0,0 +1,5 @@
package org.baeldung.di.core;
public interface IBeanB {
//
}

View File

@ -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
}

View File

@ -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() {
//
}
}