From 4f7d19e86a42172c0c49eee1c9d6e9d7b75aa666 Mon Sep 17 00:00:00 2001 From: Chris Franklin Date: Tue, 26 Dec 2017 12:19:13 -0500 Subject: [PATCH] Revert "Christopher Franklin Different Types of Bean Injection in Spring" This reverts commit d76d39fb87892a38da04105836facefbc7face5c. --- .../baeldung/beaninjectiontypes/Config.java | 16 -------- .../beaninjectiontypes/ExampleService.java | 11 ----- .../ExampleWithConstructorInjection.java | 19 --------- .../ExampleWithPropertyInjection.java | 16 -------- .../ExampleWithSetterInjection.java | 20 --------- .../beaninjectiontypes/BeanInjectionTest.java | 41 ------------------- 6 files changed, 123 deletions(-) delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleService.java delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithConstructorInjection.java delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithPropertyInjection.java delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithSetterInjection.java delete mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/BeanInjectionTest.java diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java deleted file mode 100644 index d523dc3f1f..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ComponentScan("com.baeldung.beaninjectiontypes") -public class Config { - - @Bean - public ExampleService exampleService() { - return new ExampleService(); - } - -} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleService.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleService.java deleted file mode 100644 index 9112fee577..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.stereotype.Component; - -@Component -public class ExampleService { - - public String getExampleText() { - return "Example"; - } -} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithConstructorInjection.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithConstructorInjection.java deleted file mode 100644 index 340d283dbd..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithConstructorInjection.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class ExampleWithConstructorInjection { - - private ExampleService exampleService; - - @Autowired - public ExampleWithConstructorInjection(ExampleService exampleService) { - this.exampleService = exampleService; - } - - public String verifyInjection() { - return this.exampleService.getExampleText(); - } -} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithPropertyInjection.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithPropertyInjection.java deleted file mode 100644 index d9495e5c05..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithPropertyInjection.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class ExampleWithPropertyInjection { - - @Autowired - private ExampleService exampleService; - - public String verifyInjection() { - return this.exampleService.getExampleText(); - } - -} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithSetterInjection.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithSetterInjection.java deleted file mode 100644 index 97f1355ec5..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/ExampleWithSetterInjection.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class ExampleWithSetterInjection { - - private ExampleService exampleService; - - @Autowired - public void setExampleService(ExampleService exampleService) { - this.exampleService = exampleService; - } - - public String verifyInjection() { - return this.exampleService.getExampleText(); - } - -} diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BeanInjectionTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BeanInjectionTest.java deleted file mode 100644 index ae609d5df5..0000000000 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BeanInjectionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = Config.class) -public class BeanInjectionTest { - - @Test - public void whenConstructorInjection_ThenBeanValid() { - ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); - ExampleWithConstructorInjection exampleBean = context.getBean(ExampleWithConstructorInjection.class); - - assertEquals("Example", exampleBean.verifyInjection()); - } - - @Test - public void whenSetterInjection_ThenBeanValid() { - ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); - ExampleWithSetterInjection exampleBean = context.getBean(ExampleWithSetterInjection.class); - - assertEquals("Example", exampleBean.verifyInjection()); - } - - @Test - public void whenProperyInjection_ThenBeanValid() { - ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); - ExampleWithPropertyInjection exampleBean = context.getBean(ExampleWithPropertyInjection.class); - - assertEquals("Example", exampleBean.verifyInjection()); - } - -}