diff --git a/spring-all/src/main/java/org/baeldung/sampleabstract/AbstractService.java b/spring-all/src/main/java/org/baeldung/sampleabstract/AbstractService.java deleted file mode 100644 index 51882f20b3..0000000000 --- a/spring-all/src/main/java/org/baeldung/sampleabstract/AbstractService.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.baeldung.sampleabstract; - -import org.springframework.beans.factory.annotation.Autowired; - - -public abstract class AbstractService { - - @Autowired - private FooBean fooBean; - - private BarBean barBean; - - private FooBarBean fooBarBean; - - public AbstractService(FooBarBean fooBarBean) { - - this.fooBarBean = fooBarBean; - } - - public FooBean getFooBean() { - - return fooBean; - } - - public void setFooBean(FooBean fooBean) { - - this.fooBean = fooBean; - } - - public BarBean getBarBean() { - - return barBean; - } - - @Autowired - public void setBarBean(BarBean barBean) { - - this.barBean = barBean; - } - - public FooBarBean getFooBarBean() { - - return fooBarBean; - } - - public void setFooBarBean(FooBarBean fooBarBean) { - - this.fooBarBean = fooBarBean; - } - - public void afterInitialize() { - - System.out.println(fooBean.value()); - System.out.println(barBean.value()); - System.out.println(fooBarBean.value()); - } -} diff --git a/spring-all/src/main/java/org/baeldung/sampleabstract/BallService.java b/spring-all/src/main/java/org/baeldung/sampleabstract/BallService.java new file mode 100644 index 0000000000..9a75de7fa1 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/sampleabstract/BallService.java @@ -0,0 +1,28 @@ +package org.baeldung.sampleabstract; + +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.PostConstruct; + +public abstract class BallService { + + private RuleRepository ruleRepository; + + private LogRepository logRepository; + + public BallService(RuleRepository ruleRepository) { + this.ruleRepository = ruleRepository; + } + + @Autowired + public final void setLogRepository(LogRepository logRepository) { + this.logRepository = logRepository; + } + + @PostConstruct + public void afterInitialize() { + + System.out.println(ruleRepository.toString()); + System.out.println(logRepository.toString()); + } +} diff --git a/spring-all/src/main/java/org/baeldung/sampleabstract/FooService.java b/spring-all/src/main/java/org/baeldung/sampleabstract/BasketballService.java similarity index 56% rename from spring-all/src/main/java/org/baeldung/sampleabstract/FooService.java rename to spring-all/src/main/java/org/baeldung/sampleabstract/BasketballService.java index 8bc625e098..c117231d3c 100644 --- a/spring-all/src/main/java/org/baeldung/sampleabstract/FooService.java +++ b/spring-all/src/main/java/org/baeldung/sampleabstract/BasketballService.java @@ -4,11 +4,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component -public class FooService extends AbstractService { +public class BasketballService extends BallService { @Autowired - public FooService(FooBarBean fooBarBean) { - - super(fooBarBean); + public BasketballService(RuleRepository ruleRepository) { + super(ruleRepository); } } diff --git a/spring-all/src/main/java/org/baeldung/sampleabstract/DemoApp.java b/spring-all/src/main/java/org/baeldung/sampleabstract/DemoApp.java index 0c3c4ea083..615d354ecf 100644 --- a/spring-all/src/main/java/org/baeldung/sampleabstract/DemoApp.java +++ b/spring-all/src/main/java/org/baeldung/sampleabstract/DemoApp.java @@ -1,28 +1,18 @@ package org.baeldung.sampleabstract; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import javax.annotation.PostConstruct; - @Configuration @ComponentScan(basePackages = "org.baeldung.sampleabstract") public class DemoApp { - @Autowired - private FooService fooService; public static void main(String[] args) { ApplicationContext applicationContext = new AnnotationConfigApplicationContext(DemoApp.class); } - @PostConstruct - public void afterInitialize() { - - fooService.afterInitialize(); - } } diff --git a/spring-all/src/main/java/org/baeldung/sampleabstract/FooBean.java b/spring-all/src/main/java/org/baeldung/sampleabstract/FooBean.java deleted file mode 100644 index 5ef623b5af..0000000000 --- a/spring-all/src/main/java/org/baeldung/sampleabstract/FooBean.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.baeldung.sampleabstract; - -import org.springframework.stereotype.Component; - -@Component -public class FooBean { - - public String value() { - - return "fooBean"; - } -} diff --git a/spring-all/src/main/java/org/baeldung/sampleabstract/BarBean.java b/spring-all/src/main/java/org/baeldung/sampleabstract/LogRepository.java similarity index 50% rename from spring-all/src/main/java/org/baeldung/sampleabstract/BarBean.java rename to spring-all/src/main/java/org/baeldung/sampleabstract/LogRepository.java index 8aeb5d2001..3a65671493 100644 --- a/spring-all/src/main/java/org/baeldung/sampleabstract/BarBean.java +++ b/spring-all/src/main/java/org/baeldung/sampleabstract/LogRepository.java @@ -3,10 +3,10 @@ package org.baeldung.sampleabstract; import org.springframework.stereotype.Component; @Component -public class BarBean { +public class LogRepository { - public String value() { - - return "barBean"; + @Override + public String toString() { + return "logRepository"; } } diff --git a/spring-all/src/main/java/org/baeldung/sampleabstract/FooBarBean.java b/spring-all/src/main/java/org/baeldung/sampleabstract/RuleRepository.java similarity index 50% rename from spring-all/src/main/java/org/baeldung/sampleabstract/FooBarBean.java rename to spring-all/src/main/java/org/baeldung/sampleabstract/RuleRepository.java index 0f46518a41..fd42178ab6 100644 --- a/spring-all/src/main/java/org/baeldung/sampleabstract/FooBarBean.java +++ b/spring-all/src/main/java/org/baeldung/sampleabstract/RuleRepository.java @@ -3,10 +3,10 @@ package org.baeldung.sampleabstract; import org.springframework.stereotype.Component; @Component -public class FooBarBean { +public class RuleRepository { - public String value() { - - return "fooBarBean"; + @Override + public String toString() { + return "ruleRepository"; } }