JAVA-628: Corrected README, moved article code to appropriate module
This commit is contained in:
		
							parent
							
								
									9ffb4d4d64
								
							
						
					
					
						commit
						013c4917d2
					
				| @ -13,3 +13,5 @@ This module contains articles about dependency injection with Spring | |||||||
| - [Controlling Bean Creation Order with @DependsOn Annotation](https://www.baeldung.com/spring-depends-on) | - [Controlling Bean Creation Order with @DependsOn Annotation](https://www.baeldung.com/spring-depends-on) | ||||||
| - [Unsatisfied Dependency in Spring](https://www.baeldung.com/spring-unsatisfied-dependency) | - [Unsatisfied Dependency in Spring](https://www.baeldung.com/spring-unsatisfied-dependency) | ||||||
| - [Circular Dependencies in Spring](https://www.baeldung.com/circular-dependencies-in-spring) | - [Circular Dependencies in Spring](https://www.baeldung.com/circular-dependencies-in-spring) | ||||||
|  | - [XML-Based Injection in Spring](https://www.baeldung.com/spring-xml-injection) | ||||||
|  | - More articles: [[next -->]](/spring-di-2) | ||||||
|  | |||||||
| @ -1,13 +0,0 @@ | |||||||
| package com.baeldung.dependency; |  | ||||||
| 
 |  | ||||||
| import org.springframework.stereotype.Component; |  | ||||||
| 
 |  | ||||||
| @Component |  | ||||||
| public class AnotherArbitraryDependency extends ArbitraryDependency { |  | ||||||
| 
 |  | ||||||
|     private final String label = "Another Arbitrary Dependency"; |  | ||||||
| 
 |  | ||||||
|     public String toString() { |  | ||||||
|         return label; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,13 +0,0 @@ | |||||||
| package com.baeldung.dependency; |  | ||||||
| 
 |  | ||||||
| import org.springframework.stereotype.Component; |  | ||||||
| 
 |  | ||||||
| @Component(value = "autowiredFieldDependency") |  | ||||||
| public class ArbitraryDependency { |  | ||||||
| 
 |  | ||||||
|     private final String label = "Arbitrary Dependency"; |  | ||||||
| 
 |  | ||||||
|     public String toString() { |  | ||||||
|         return label; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,13 +0,0 @@ | |||||||
| package com.baeldung.dependency; |  | ||||||
| 
 |  | ||||||
| import org.springframework.stereotype.Component; |  | ||||||
| 
 |  | ||||||
| @Component |  | ||||||
| public class YetAnotherArbitraryDependency extends ArbitraryDependency { |  | ||||||
| 
 |  | ||||||
|     private final String label = "Yet Another Arbitrary Dependency"; |  | ||||||
| 
 |  | ||||||
|     public String toString() { |  | ||||||
|         return label; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,29 +0,0 @@ | |||||||
| package com.baeldung.autowired; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.configuration.ApplicationContextTestAutowiredType; |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |  | ||||||
| import org.springframework.test.context.support.AnnotationConfigContextLoader; |  | ||||||
| 
 |  | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| import static org.junit.Assert.assertNotNull; |  | ||||||
| 
 |  | ||||||
| @RunWith(SpringJUnit4ClassRunner.class) |  | ||||||
| @ContextConfiguration( |  | ||||||
|   loader = AnnotationConfigContextLoader.class, |  | ||||||
|   classes = ApplicationContextTestAutowiredType.class) |  | ||||||
| public class FieldAutowiredIntegrationTest { |  | ||||||
| 
 |  | ||||||
|     @Autowired |  | ||||||
|     private ArbitraryDependency fieldDependency; |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     public void givenAutowired_WhenSetOnField_ThenDependencyResolved() { |  | ||||||
|         assertNotNull(fieldDependency); |  | ||||||
|         assertEquals("Arbitrary Dependency", fieldDependency.toString()); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,29 +0,0 @@ | |||||||
| package com.baeldung.autowired; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.configuration.ApplicationContextTestAutowiredName; |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |  | ||||||
| import org.springframework.test.context.support.AnnotationConfigContextLoader; |  | ||||||
| 
 |  | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| import static org.junit.Assert.assertNotNull; |  | ||||||
| 
 |  | ||||||
| @RunWith(SpringJUnit4ClassRunner.class) |  | ||||||
| @ContextConfiguration( |  | ||||||
|   loader = AnnotationConfigContextLoader.class, |  | ||||||
|   classes = ApplicationContextTestAutowiredName.class) |  | ||||||
| public class FieldAutowiredNameIntegrationTest { |  | ||||||
| 
 |  | ||||||
|     @Autowired |  | ||||||
|     private ArbitraryDependency autowiredFieldDependency; |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     public void givenAutowiredAnnotation_WhenOnField_ThenDependencyValid() { |  | ||||||
|         assertNotNull(autowiredFieldDependency); |  | ||||||
|         assertEquals("Arbitrary Dependency", autowiredFieldDependency.toString()); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,41 +0,0 @@ | |||||||
| package com.baeldung.autowired; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.configuration.ApplicationContextTestAutowiredQualifier; |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||||
| import org.springframework.beans.factory.annotation.Qualifier; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |  | ||||||
| import org.springframework.test.context.support.AnnotationConfigContextLoader; |  | ||||||
| 
 |  | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| import static org.junit.Assert.assertNotNull; |  | ||||||
| 
 |  | ||||||
| @RunWith(SpringJUnit4ClassRunner.class) |  | ||||||
| @ContextConfiguration( |  | ||||||
|   loader = AnnotationConfigContextLoader.class, |  | ||||||
|   classes = ApplicationContextTestAutowiredQualifier.class) |  | ||||||
| public class FieldQualifierAutowiredIntegrationTest { |  | ||||||
| 
 |  | ||||||
|     @Autowired |  | ||||||
|     @Qualifier("autowiredFieldDependency") |  | ||||||
|     private ArbitraryDependency fieldDependency1; |  | ||||||
| 
 |  | ||||||
|     @Autowired |  | ||||||
|     @Qualifier("anotherAutowiredFieldDependency") |  | ||||||
|     private ArbitraryDependency fieldDependency2; |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     public void givenAutowiredQualifier_WhenOnField_ThenDep1Valid() { |  | ||||||
|         assertNotNull(fieldDependency1); |  | ||||||
|         assertEquals("Arbitrary Dependency", fieldDependency1.toString()); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     public void givenAutowiredQualifier_WhenOnField_ThenDep2Valid() { |  | ||||||
|         assertNotNull(fieldDependency2); |  | ||||||
|         assertEquals("Another Arbitrary Dependency", fieldDependency2.toString()); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,9 +0,0 @@ | |||||||
| package com.baeldung.configuration; |  | ||||||
| 
 |  | ||||||
| import org.springframework.context.annotation.ComponentScan; |  | ||||||
| import org.springframework.context.annotation.Configuration; |  | ||||||
| 
 |  | ||||||
| @Configuration |  | ||||||
| @ComponentScan(basePackages = {"com.baeldung.dependency"}) |  | ||||||
| public class ApplicationContextTestAutowiredName { |  | ||||||
| } |  | ||||||
| @ -1,24 +0,0 @@ | |||||||
| package com.baeldung.configuration; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.dependency.AnotherArbitraryDependency; |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import org.springframework.context.annotation.Bean; |  | ||||||
| import org.springframework.context.annotation.Configuration; |  | ||||||
| 
 |  | ||||||
| @Configuration |  | ||||||
| public class ApplicationContextTestAutowiredQualifier { |  | ||||||
| 
 |  | ||||||
|     @Bean |  | ||||||
|     public ArbitraryDependency autowiredFieldDependency() { |  | ||||||
|         ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency(); |  | ||||||
| 
 |  | ||||||
|         return autowiredFieldDependency; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Bean |  | ||||||
|     public ArbitraryDependency anotherAutowiredFieldDependency() { |  | ||||||
|         ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency(); |  | ||||||
| 
 |  | ||||||
|         return anotherAutowiredFieldDependency; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,15 +0,0 @@ | |||||||
| package com.baeldung.configuration; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import org.springframework.context.annotation.Bean; |  | ||||||
| import org.springframework.context.annotation.Configuration; |  | ||||||
| 
 |  | ||||||
| @Configuration |  | ||||||
| public class ApplicationContextTestAutowiredType { |  | ||||||
| 
 |  | ||||||
|     @Bean |  | ||||||
|     public ArbitraryDependency autowiredFieldDependency() { |  | ||||||
|         ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency(); |  | ||||||
|         return autowiredFieldDependency; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,16 +0,0 @@ | |||||||
| package com.baeldung.configuration; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import com.baeldung.dependency.YetAnotherArbitraryDependency; |  | ||||||
| import org.springframework.context.annotation.Bean; |  | ||||||
| import org.springframework.context.annotation.Configuration; |  | ||||||
| 
 |  | ||||||
| @Configuration |  | ||||||
| public class ApplicationContextTestInjectName { |  | ||||||
| 
 |  | ||||||
|     @Bean |  | ||||||
|     public ArbitraryDependency yetAnotherFieldInjectDependency() { |  | ||||||
|         ArbitraryDependency yetAnotherFieldInjectDependency = new YetAnotherArbitraryDependency(); |  | ||||||
|         return yetAnotherFieldInjectDependency; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,22 +0,0 @@ | |||||||
| package com.baeldung.configuration; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.dependency.AnotherArbitraryDependency; |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import org.springframework.context.annotation.Bean; |  | ||||||
| import org.springframework.context.annotation.Configuration; |  | ||||||
| 
 |  | ||||||
| @Configuration |  | ||||||
| public class ApplicationContextTestInjectQualifier { |  | ||||||
| 
 |  | ||||||
|     @Bean |  | ||||||
|     public ArbitraryDependency defaultFile() { |  | ||||||
|         ArbitraryDependency defaultFile = new ArbitraryDependency(); |  | ||||||
|         return defaultFile; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Bean |  | ||||||
|     public ArbitraryDependency namedFile() { |  | ||||||
|         ArbitraryDependency namedFile = new AnotherArbitraryDependency(); |  | ||||||
|         return namedFile; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,15 +0,0 @@ | |||||||
| package com.baeldung.configuration; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import org.springframework.context.annotation.Bean; |  | ||||||
| import org.springframework.context.annotation.Configuration; |  | ||||||
| 
 |  | ||||||
| @Configuration |  | ||||||
| public class ApplicationContextTestInjectType { |  | ||||||
| 
 |  | ||||||
|     @Bean |  | ||||||
|     public ArbitraryDependency injectDependency() { |  | ||||||
|         ArbitraryDependency injectDependency = new ArbitraryDependency(); |  | ||||||
|         return injectDependency; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,32 +0,0 @@ | |||||||
| package com.baeldung.inject; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.configuration.ApplicationContextTestInjectName; |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| 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; |  | ||||||
| 
 |  | ||||||
| import javax.inject.Inject; |  | ||||||
| import javax.inject.Named; |  | ||||||
| 
 |  | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| import static org.junit.Assert.assertNotNull; |  | ||||||
| 
 |  | ||||||
| @RunWith(SpringJUnit4ClassRunner.class) |  | ||||||
| @ContextConfiguration( |  | ||||||
|   loader = AnnotationConfigContextLoader.class, |  | ||||||
|   classes = ApplicationContextTestInjectName.class) |  | ||||||
| public class FieldByNameInjectIntegrationTest { |  | ||||||
| 
 |  | ||||||
|     @Inject |  | ||||||
|     @Named("yetAnotherFieldInjectDependency") |  | ||||||
|     private ArbitraryDependency yetAnotherFieldInjectDependency; |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() { |  | ||||||
|         assertNotNull(yetAnotherFieldInjectDependency); |  | ||||||
|         assertEquals("Yet Another Arbitrary Dependency", yetAnotherFieldInjectDependency.toString()); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,30 +0,0 @@ | |||||||
| package com.baeldung.inject; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.configuration.ApplicationContextTestInjectType; |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| 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; |  | ||||||
| 
 |  | ||||||
| import javax.inject.Inject; |  | ||||||
| 
 |  | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| import static org.junit.Assert.assertNotNull; |  | ||||||
| 
 |  | ||||||
| @RunWith(SpringJUnit4ClassRunner.class) |  | ||||||
| @ContextConfiguration( |  | ||||||
|   loader = AnnotationConfigContextLoader.class, |  | ||||||
|   classes = ApplicationContextTestInjectType.class) |  | ||||||
| public class FieldInjectIntegrationTest { |  | ||||||
| 
 |  | ||||||
|     @Inject |  | ||||||
|     private ArbitraryDependency fieldInjectDependency; |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     public void givenInjectAnnotation_WhenOnField_ThenValidDependency() { |  | ||||||
|         assertNotNull(fieldInjectDependency); |  | ||||||
|         assertEquals("Arbitrary Dependency", fieldInjectDependency.toString()); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,41 +0,0 @@ | |||||||
| package com.baeldung.inject; |  | ||||||
| 
 |  | ||||||
| import com.baeldung.configuration.ApplicationContextTestInjectQualifier; |  | ||||||
| import com.baeldung.dependency.ArbitraryDependency; |  | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| import org.springframework.beans.factory.annotation.Qualifier; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |  | ||||||
| import org.springframework.test.context.support.AnnotationConfigContextLoader; |  | ||||||
| 
 |  | ||||||
| import javax.inject.Inject; |  | ||||||
| 
 |  | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| import static org.junit.Assert.assertNotNull; |  | ||||||
| 
 |  | ||||||
| @RunWith(SpringJUnit4ClassRunner.class) |  | ||||||
| @ContextConfiguration(loader = AnnotationConfigContextLoader.class, |  | ||||||
|   classes = ApplicationContextTestInjectQualifier.class) |  | ||||||
| public class FieldQualifierInjectIntegrationTest { |  | ||||||
| 
 |  | ||||||
|     @Inject |  | ||||||
|     @Qualifier("defaultFile") |  | ||||||
|     private ArbitraryDependency defaultDependency; |  | ||||||
| 
 |  | ||||||
|     @Inject |  | ||||||
|     @Qualifier("namedFile") |  | ||||||
|     private ArbitraryDependency namedDependency; |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid() { |  | ||||||
|         assertNotNull(defaultDependency); |  | ||||||
|         assertEquals("Arbitrary Dependency", defaultDependency.toString()); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     public void givenInjectQualifier_WhenOnField_ThenNamedFileValid() { |  | ||||||
|         assertNotNull(defaultDependency); |  | ||||||
|         assertEquals("Another Arbitrary Dependency", namedDependency.toString()); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user