From df1c303782c67e1975f055f3c7a562291eeea1ef Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Mon, 28 Sep 2020 01:24:17 +0200 Subject: [PATCH] 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 { +}