1- package com .baeldung .setterdi ;
2-
3- import org .springframework .context .annotation .Bean ;
4- import org .springframework .context .annotation .ComponentScan ;
5- import org .springframework .context .annotation .Configuration ;
6-
7- import com .baeldung .setterdi .domain .Engine ;
8- import com .baeldung .setterdi .domain .Trailer ;
9- import com .baeldung .setterdi .domain .Transmission ;
10-
11- @ Configuration
12- @ ComponentScan ("com.baeldung.setterdi" )
13- public class Config {
14-
15- @ Bean
16- public Engine engine () {
17- Engine engine = new Engine ();
18- engine .setType ("v8" );
19- engine .setVolume (5 );
20- return engine ;
21- }
22-
23- @ Bean
24- public Transmission transmission () {
25- Transmission transmission = new Transmission ();
26- transmission .setType ("sliding" );
27- return transmission ;
28- }
29-
30- @ Bean
31- public Trailer trailer () {
32- Trailer trailer = new Trailer ();
33- return trailer ;
34- }
1+ package com .baeldung .setterdi ;
2+
3+ import org .springframework .context .annotation .Bean ;
4+ import org .springframework .context .annotation .ComponentScan ;
5+ import org .springframework .context .annotation .Configuration ;
6+
7+ import com .baeldung .dependencyinjectiontypes .Student ;
8+ import com .baeldung .dependencyinjectiontypes .Student2 ;
9+ import com .baeldung .dependencyinjectiontypes .TeacherFinder ;
10+ import com .baeldung .setterdi .domain .Engine ;
11+ import com .baeldung .setterdi .domain .Trailer ;
12+ import com .baeldung .setterdi .domain .Transmission ;
13+
14+ @ Configuration
15+ @ ComponentScan ("com.baeldung.setterdi" )
16+ public class Config {
17+
18+ @ Bean
19+ public Engine engine () {
20+ Engine engine = new Engine ();
21+ engine .setType ("v8" );
22+ engine .setVolume (5 );
23+ return engine ;
24+ }
25+
26+ @ Bean
27+ public Transmission transmission () {
28+ Transmission transmission = new Transmission ();
29+ transmission .setType ("sliding" );
30+ return transmission ;
31+ }
32+
33+ @ Bean
34+ public Trailer trailer () {
35+ Trailer trailer = new Trailer ();
36+ return trailer ;
37+ }
38+
39+ @ Bean
40+ public TeacherFinder teacherFinder (){
41+ TeacherFinder teacherFinder =new TeacherFinder ();
42+ teacherFinder .setTeacherFinder ("author" );
43+ return teacherFinder ;
44+ }
45+
46+ @ Bean
47+ public Student student () {
48+ return new Student (teacherFinder ());
49+ }
50+
51+ @ Bean
52+ public Student2 student2 () {
53+ Student2 student2 = new Student2 ();
54+ student2 .setTeacherFinder (teacherFinder ());
55+ return student2 ;
56+ }
57+
3558}
0 commit comments