Added component scan and auto configuration annotations

This commit is contained in:
Anirban Chatterjee 2020-09-28 01:24:17 +02:00
parent e3d721b72c
commit 29c91cde2e
6 changed files with 61 additions and 0 deletions

View File

@ -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"));
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.annotations.componentscanautoconfigure.doctor;
import org.springframework.stereotype.Component;
@Component("doctor")
public class Doctor {
}

View File

@ -0,0 +1,7 @@
package com.baeldung.annotations.componentscanautoconfigure.employee;
import org.springframework.stereotype.Component;
@Component("employee")
public class Employee {
}

View File

@ -0,0 +1,7 @@
package com.baeldung.annotations.componentscanautoconfigure.employee;
import org.springframework.stereotype.Component;
@Component("seniorEmployee")
public class SeniorEmployee {
}

View File

@ -0,0 +1,7 @@
package com.baeldung.annotations.componentscanautoconfigure.student;
import org.springframework.stereotype.Component;
@Component("student")
public class Student {
}

View File

@ -0,0 +1,7 @@
package com.baeldung.annotations.componentscanautoconfigure.teacher;
import org.springframework.stereotype.Component;
@Component("teacher")
public class Teacher {
}