File tree Expand file tree Collapse file tree
spring-all/src/main/java/org/baeldung/sampleabstract Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package org .baeldung .sampleabstract ;
2+
3+ import org .springframework .beans .factory .annotation .Autowired ;
4+
5+ import javax .annotation .PostConstruct ;
6+
7+ public abstract class BallService {
8+
9+ private RuleRepository ruleRepository ;
10+
11+ private LogRepository logRepository ;
12+
13+ public BallService (RuleRepository ruleRepository ) {
14+ this .ruleRepository = ruleRepository ;
15+ }
16+
17+ @ Autowired
18+ public final void setLogRepository (LogRepository logRepository ) {
19+ this .logRepository = logRepository ;
20+ }
21+
22+ @ PostConstruct
23+ public void afterInitialize () {
24+
25+ System .out .println (ruleRepository .toString ());
26+ System .out .println (logRepository .toString ());
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package org .baeldung .sampleabstract ;
2+
3+ import org .springframework .beans .factory .annotation .Autowired ;
4+ import org .springframework .stereotype .Component ;
5+
6+ @ Component
7+ public class BasketballService extends BallService {
8+
9+ @ Autowired
10+ public BasketballService (RuleRepository ruleRepository ) {
11+ super (ruleRepository );
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ package org .baeldung .sampleabstract ;
2+
3+ import org .springframework .context .ApplicationContext ;
4+ import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
5+ import org .springframework .context .annotation .ComponentScan ;
6+ import org .springframework .context .annotation .Configuration ;
7+
8+ @ Configuration
9+ @ ComponentScan (basePackages = "org.baeldung.sampleabstract" )
10+ public class DemoApp {
11+
12+
13+ public static void main (String [] args ) {
14+
15+ ApplicationContext applicationContext = new AnnotationConfigApplicationContext (DemoApp .class );
16+ }
17+
18+ }
Original file line number Diff line number Diff line change 1+ package org .baeldung .sampleabstract ;
2+
3+ import org .springframework .stereotype .Component ;
4+
5+ @ Component
6+ public class LogRepository {
7+
8+ @ Override
9+ public String toString () {
10+ return "logRepository" ;
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ package org .baeldung .sampleabstract ;
2+
3+ import org .springframework .stereotype .Component ;
4+
5+ @ Component
6+ public class RuleRepository {
7+
8+ @ Override
9+ public String toString () {
10+ return "ruleRepository" ;
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments