Files
spring-boot-rest/spring-boot-di/src/main/java/com/baeldung/componentscan/springbootapp/SpringBootComponentScanApp.java
Devender Kumar 56cae916aa remove sys and added test cases (#7894)
* BAEL-3286 added component scan filter example

* Remove unused class

* Corrected formatting

* formatted code

* Update code

* added test cases

* Fix tests name
2019-09-29 08:38:58 -07:00

35 lines
1.3 KiB
Java

package com.baeldung.componentscan.springbootapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import com.baeldung.componentscan.ExampleBean;
@SpringBootApplication
// @ComponentScan(basePackages = "com.baeldung.componentscan.springbootapp.animals")
// @ComponentScan ( excludeFilters = @ComponentScan.Filter(type=FilterType.REGEX,pattern="com\\.baeldung\\.componentscan\\.springbootapp\\.flowers\\..*"))
// @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = Rose.class))
public class SpringBootComponentScanApp {
private static ApplicationContext applicationContext;
@Bean
public ExampleBean exampleBean() {
return new ExampleBean();
}
public static void main(String[] args) {
applicationContext = SpringApplication.run(SpringBootComponentScanApp.class, args);
checkBeansPresence("cat", "dog", "rose", "exampleBean", "springBootApp");
}
private static void checkBeansPresence(String... beans) {
for (String beanName : beans) {
System.out.println("Is " + beanName + " in ApplicationContext: " + applicationContext.containsBean(beanName));
}
}
}