From 29c91cde2e39b7dbb8c29ffde57444da97e6914c Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Mon, 28 Sep 2020 01:24:17 +0200 Subject: [PATCH 1/5] Added component scan and auto configuration annotations --- .../EmployeeApplication.java | 26 +++++++++++++++++++ .../doctor/Doctor.java | 7 +++++ .../employee/Employee.java | 7 +++++ .../employee/SeniorEmployee.java | 7 +++++ .../student/Student.java | 7 +++++ .../teacher/Teacher.java | 7 +++++ 6 files changed, 61 insertions(+) create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/doctor/Doctor.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/Employee.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/student/Student.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/teacher/Teacher.java diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java new file mode 100644 index 0000000000..108dd1a695 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java @@ -0,0 +1,26 @@ +package com.baeldung.annotations.componentscanautoconfigure; + +import com.baeldung.annotations.componentscanautoconfigure.teacher.Teacher; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan(basePackages = {"com.baeldung.annotations.componentscanautoconfigure.doctor", "com.baeldung.annotations.componentscanautoconfigure.employee"}, + basePackageClasses = Teacher.class) +@EnableAutoConfiguration(exclude={AopAutoConfiguration.class}) +//@EnableAutoConfiguration(excludeName = {"org.springframework.boot.autoconfigure.aop"}) +public class EmployeeApplication { + + public static void main(String[] args) { + ApplicationContext context = SpringApplication.run(EmployeeApplication.class, args); + System.out.println("Configures Doctor: " + context.containsBeanDefinition("doctor")); + System.out.println("Configures Employee: " + context.containsBeanDefinition("employee")); + System.out.println("Configures Senior Employee: " + context.containsBeanDefinition("seniorEmployee")); + System.out.println("Configures Student: " + context.containsBeanDefinition("student")); + System.out.println("Configures Teacher: " + context.containsBeanDefinition("teacher")); + } +} diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/doctor/Doctor.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/doctor/Doctor.java new file mode 100644 index 0000000000..40bb68259a --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/doctor/Doctor.java @@ -0,0 +1,7 @@ +package com.baeldung.annotations.componentscanautoconfigure.doctor; + +import org.springframework.stereotype.Component; + +@Component("doctor") +public class Doctor { +} diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/Employee.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/Employee.java new file mode 100644 index 0000000000..bdc0b3f2d9 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/Employee.java @@ -0,0 +1,7 @@ +package com.baeldung.annotations.componentscanautoconfigure.employee; + +import org.springframework.stereotype.Component; + +@Component("employee") +public class Employee { +} diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java new file mode 100644 index 0000000000..fc02a17df6 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java @@ -0,0 +1,7 @@ +package com.baeldung.annotations.componentscanautoconfigure.employee; + +import org.springframework.stereotype.Component; + +@Component("seniorEmployee") +public class SeniorEmployee { +} diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/student/Student.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/student/Student.java new file mode 100644 index 0000000000..820d0bea10 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/student/Student.java @@ -0,0 +1,7 @@ +package com.baeldung.annotations.componentscanautoconfigure.student; + +import org.springframework.stereotype.Component; + +@Component("student") +public class Student { +} diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/teacher/Teacher.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/teacher/Teacher.java new file mode 100644 index 0000000000..699b8ccfb4 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/teacher/Teacher.java @@ -0,0 +1,7 @@ +package com.baeldung.annotations.componentscanautoconfigure.teacher; + +import org.springframework.stereotype.Component; + +@Component("teacher") +public class Teacher { +} From 427581b3a64807d552f0cd58d9c858177121840d Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Mon, 28 Sep 2020 23:21:40 +0200 Subject: [PATCH 2/5] Code cleanup --- .../componentscanautoconfigure/EmployeeApplication.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java index 108dd1a695..d429b0cdc9 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java @@ -3,7 +3,7 @@ package com.baeldung.annotations.componentscanautoconfigure; import com.baeldung.annotations.componentscanautoconfigure.teacher.Teacher; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -11,8 +11,8 @@ import org.springframework.context.annotation.Configuration; @Configuration @ComponentScan(basePackages = {"com.baeldung.annotations.componentscanautoconfigure.doctor", "com.baeldung.annotations.componentscanautoconfigure.employee"}, basePackageClasses = Teacher.class) -@EnableAutoConfiguration(exclude={AopAutoConfiguration.class}) -//@EnableAutoConfiguration(excludeName = {"org.springframework.boot.autoconfigure.aop"}) +@EnableAutoConfiguration(exclude={JdbcTemplateAutoConfiguration.class}) +//@EnableAutoConfiguration(excludeName = {"org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration"}) public class EmployeeApplication { public static void main(String[] args) { From 14593ca02a9a316657a929c1cda6cf664d4beab8 Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Sun, 4 Oct 2020 12:55:22 +0200 Subject: [PATCH 3/5] Refined bean methods --- .../EmployeeApplication.java | 9 +++++---- .../componentscanautoconfigure/doctor/Doctor.java | 7 ------- .../employee/SeniorEmployee.java | 2 +- .../healthcare/Doctor.java | 9 +++++++++ .../healthcare/Hospital.java | 13 +++++++++++++ 5 files changed, 28 insertions(+), 12 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/doctor/Doctor.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/healthcare/Doctor.java create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/healthcare/Hospital.java diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java index d429b0cdc9..578479a81c 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java @@ -8,18 +8,19 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -@Configuration -@ComponentScan(basePackages = {"com.baeldung.annotations.componentscanautoconfigure.doctor", "com.baeldung.annotations.componentscanautoconfigure.employee"}, +//@Configuration +@ComponentScan(basePackages = {"com.baeldung.annotations.componentscanautoconfigure.healthcare", "com.baeldung.annotations.componentscanautoconfigure.employee"}, basePackageClasses = Teacher.class) -@EnableAutoConfiguration(exclude={JdbcTemplateAutoConfiguration.class}) +@EnableAutoConfiguration(exclude = {JdbcTemplateAutoConfiguration.class}) //@EnableAutoConfiguration(excludeName = {"org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration"}) public class EmployeeApplication { public static void main(String[] args) { ApplicationContext context = SpringApplication.run(EmployeeApplication.class, args); - System.out.println("Configures Doctor: " + context.containsBeanDefinition("doctor")); System.out.println("Configures Employee: " + context.containsBeanDefinition("employee")); System.out.println("Configures Senior Employee: " + context.containsBeanDefinition("seniorEmployee")); + System.out.println("Configures Doctor: " + context.containsBeanDefinition("doctor")); + System.out.println("Configures Hospital: " + context.containsBeanDefinition("hospital")); System.out.println("Configures Student: " + context.containsBeanDefinition("student")); System.out.println("Configures Teacher: " + context.containsBeanDefinition("teacher")); } diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/doctor/Doctor.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/doctor/Doctor.java deleted file mode 100644 index 40bb68259a..0000000000 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/doctor/Doctor.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.annotations.componentscanautoconfigure.doctor; - -import org.springframework.stereotype.Component; - -@Component("doctor") -public class Doctor { -} diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java index fc02a17df6..ef75b4af0a 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java @@ -2,6 +2,6 @@ package com.baeldung.annotations.componentscanautoconfigure.employee; import org.springframework.stereotype.Component; -@Component("seniorEmployee") +@Component public class SeniorEmployee { } diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/healthcare/Doctor.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/healthcare/Doctor.java new file mode 100644 index 0000000000..7e7e6cb03b --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/healthcare/Doctor.java @@ -0,0 +1,9 @@ +package com.baeldung.annotations.componentscanautoconfigure.healthcare; + +public class Doctor { + + @Override + public String toString() { + return "Doctor" + this.hashCode(); + } +} diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/healthcare/Hospital.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/healthcare/Hospital.java new file mode 100644 index 0000000000..0711544060 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/healthcare/Hospital.java @@ -0,0 +1,13 @@ +package com.baeldung.annotations.componentscanautoconfigure.healthcare; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class Hospital { + + @Bean("doctor") + public Doctor getDoctor() { + return new Doctor(); + } +} From bd53673e2b175f9450829b20e5e81394ab7b0ac3 Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Tue, 6 Oct 2020 22:33:24 +0200 Subject: [PATCH 4/5] Added unit test --- .../EmployeeApplication.java | 8 +++---- .../EmployeeApplicationTest.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) rename spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/{componentscanautoconfigure => }/EmployeeApplication.java (86%) create mode 100644 spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/EmployeeApplication.java similarity index 86% rename from spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java rename to spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/EmployeeApplication.java index 578479a81c..263df30e16 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/EmployeeApplication.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/EmployeeApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.annotations.componentscanautoconfigure; +package com.baeldung.annotations; import com.baeldung.annotations.componentscanautoconfigure.teacher.Teacher; import org.springframework.boot.SpringApplication; @@ -6,15 +6,13 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -//@Configuration -@ComponentScan(basePackages = {"com.baeldung.annotations.componentscanautoconfigure.healthcare", "com.baeldung.annotations.componentscanautoconfigure.employee"}, +@ComponentScan(basePackages = {"com.baeldung.annotations.componentscanautoconfigure.healthcare", + "com.baeldung.annotations.componentscanautoconfigure.employee"}, basePackageClasses = Teacher.class) @EnableAutoConfiguration(exclude = {JdbcTemplateAutoConfiguration.class}) //@EnableAutoConfiguration(excludeName = {"org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration"}) public class EmployeeApplication { - public static void main(String[] args) { ApplicationContext context = SpringApplication.run(EmployeeApplication.class, args); System.out.println("Configures Employee: " + context.containsBeanDefinition("employee")); diff --git a/spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java b/spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java new file mode 100644 index 0000000000..66700cf781 --- /dev/null +++ b/spring-boot-modules/spring-boot-annotations/src/main/test/com.baeldung.annotations/EmployeeApplicationTest.java @@ -0,0 +1,23 @@ +package com.baeldung.annotations; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertAll; + +public class EmployeeApplicationTest { + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withUserConfiguration(EmployeeApplication.class); + + @Test + void whenApplicationContextRuns_thenContainAllDefinedBeans() { + contextRunner.run(context -> assertAll( + () -> assertTrue(context.containsBeanDefinition("employee")), + () -> assertTrue(context.containsBeanDefinition("seniorEmployee")), + () -> assertTrue(context.containsBeanDefinition("doctor")), + () -> assertTrue(context.containsBeanDefinition("hospital")), + () -> assertFalse(context.containsBeanDefinition("student")), + () -> assertTrue(context.containsBeanDefinition("teacher")))); + } +} From d27cbbc4a6507d3ba0a76057c34cd6cdf4b21e8c Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Wed, 7 Oct 2020 09:32:33 +0200 Subject: [PATCH 5/5] Removed boilerplate code --- .../com/baeldung/annotations/EmployeeApplication.java | 8 +------- .../componentscanautoconfigure/employee/Employee.java | 5 +++++ .../employee/SeniorEmployee.java | 5 +++++ .../componentscanautoconfigure/student/Student.java | 5 +++++ .../componentscanautoconfigure/teacher/Teacher.java | 5 +++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/EmployeeApplication.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/EmployeeApplication.java index 263df30e16..17c7af858b 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/EmployeeApplication.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/EmployeeApplication.java @@ -14,12 +14,6 @@ import org.springframework.context.annotation.ComponentScan; //@EnableAutoConfiguration(excludeName = {"org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration"}) public class EmployeeApplication { public static void main(String[] args) { - ApplicationContext context = SpringApplication.run(EmployeeApplication.class, args); - System.out.println("Configures Employee: " + context.containsBeanDefinition("employee")); - System.out.println("Configures Senior Employee: " + context.containsBeanDefinition("seniorEmployee")); - System.out.println("Configures Doctor: " + context.containsBeanDefinition("doctor")); - System.out.println("Configures Hospital: " + context.containsBeanDefinition("hospital")); - System.out.println("Configures Student: " + context.containsBeanDefinition("student")); - System.out.println("Configures Teacher: " + context.containsBeanDefinition("teacher")); + SpringApplication.run(EmployeeApplication.class, args); } } diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/Employee.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/Employee.java index bdc0b3f2d9..9be3388046 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/Employee.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/Employee.java @@ -4,4 +4,9 @@ import org.springframework.stereotype.Component; @Component("employee") public class Employee { + + @Override + public String toString() { + return "Employee" + this.hashCode(); + } } diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java index ef75b4af0a..242e84f887 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/employee/SeniorEmployee.java @@ -4,4 +4,9 @@ import org.springframework.stereotype.Component; @Component public class SeniorEmployee { + + @Override + public String toString() { + return "Senior Employee" + this.hashCode(); + } } diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/student/Student.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/student/Student.java index 820d0bea10..56f2ac9830 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/student/Student.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/student/Student.java @@ -4,4 +4,9 @@ import org.springframework.stereotype.Component; @Component("student") public class Student { + + @Override + public String toString() { + return "Student" + this.hashCode(); + } } diff --git a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/teacher/Teacher.java b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/teacher/Teacher.java index 699b8ccfb4..e2c653204d 100644 --- a/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/teacher/Teacher.java +++ b/spring-boot-modules/spring-boot-annotations/src/main/java/com/baeldung/annotations/componentscanautoconfigure/teacher/Teacher.java @@ -4,4 +4,9 @@ import org.springframework.stereotype.Component; @Component("teacher") public class Teacher { + + @Override + public String toString() { + return "Teacher" + this.hashCode(); + } }