* BAEL-2072

* rename
This commit is contained in:
myluckagain 2018-08-19 12:36:54 +05:00 committed by Predrag Maric
parent c1f4486a27
commit 351f2bc98c
9 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package com.baeldung.componentscan;
public class ExampleBean {
}

View File

@ -0,0 +1,38 @@
package com.baeldung.componentscan.springapp;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Component;
import com.baeldung.componentscan.ExampleBean;
import com.baeldung.componentscan.springapp.flowers.Rose;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
//@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = Rose.class))
//@ComponentScan(basePackages = "com.baeldung.componentscan.springapp")
//@ComponentScan(basePackages = "com.baeldung.componentscan.springapp.animals")
//@ComponentScan (excludeFilters = @ComponentScan.Filter(type=FilterType.REGEX,pattern="com\\.baeldung\\.componentscan\\.springapp\\.flowers\\..*"))
public class SpringComponentScanApp {
private static ApplicationContext applicationContext;
@Bean
public ExampleBean exampleBean() {
return new ExampleBean();
}
public static void main(String[] args) {
applicationContext = new AnnotationConfigApplicationContext(SpringComponentScanApp.class);
for (String beanName : applicationContext.getBeanDefinitionNames()) {
System.out.println(beanName);
}
}
}

View File

@ -0,0 +1,8 @@
package com.baeldung.componentscan.springapp.animals;
import org.springframework.stereotype.Component;
@Component
public class Cat {
}

View File

@ -0,0 +1,8 @@
package com.baeldung.componentscan.springapp.animals;
import org.springframework.stereotype.Component;
@Component
public class Dog {
}

View File

@ -0,0 +1,8 @@
package com.baeldung.componentscan.springapp.flowers;
import org.springframework.stereotype.Component;
@Component
public class Rose {
}

View File

@ -0,0 +1,37 @@
package com.baeldung.componentscan.springbootapp;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.FilterType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import com.baeldung.componentscan.ExampleBean;
import com.baeldung.componentscan.springbootapp.flowers.Rose;
@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));
}
}
}

View File

@ -0,0 +1,8 @@
package com.baeldung.componentscan.springbootapp.animals;
import org.springframework.stereotype.Component;
@Component
public class Cat {
}

View File

@ -0,0 +1,8 @@
package com.baeldung.componentscan.springbootapp.animals;
import org.springframework.stereotype.Component;
@Component
public class Dog {
}

View File

@ -0,0 +1,8 @@
package com.baeldung.componentscan.springbootapp.flowers;
import org.springframework.stereotype.Component;
@Component
public class Rose {
}