Refined bean methods

This commit is contained in:
Anirban Chatterjee 2020-10-04 12:55:22 +02:00
parent 427581b3a6
commit 14593ca02a
5 changed files with 28 additions and 12 deletions

View File

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

View File

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

View File

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

View File

@ -0,0 +1,9 @@
package com.baeldung.annotations.componentscanautoconfigure.healthcare;
public class Doctor {
@Override
public String toString() {
return "Doctor" + this.hashCode();
}
}

View File

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