educative.io

Educative

Component Scan related issue in Spring course

lesson10 package contains CollaborativeFilter.java

lesson9 package contains ContentBasedFilter.java

Case 1:
//SpringBootApplication (commented)
ComponentScan(basePackages=“io.datajek.spring.basics.movierecommendersystem.lesson10”)
ComponentScan(includeFilters = @ComponentScan.Filter (type= FilterType.REGEX, pattern=“io.datajek.spring.basics.movierecommendersystem.lesson9.*”))

In this case : CollaborativeFilter bean found = false
ContentBasedFilter bean found = false.

Case 2 :
SpringBootApplication (Uncommented)
ComponentScan(basePackages=“io.datajek.spring.basics.movierecommendersystem.lesson10”)
ComponentScan(includeFilters = @ComponentScan.Filter (type= FilterType.REGEX, pattern=“io.datajek.spring.basics.movierecommendersystem.lesson9.*”))

In this case : CollaborativeFilter bean found = True.
ContentBasedFilter bean found = True.

Case 3 :
//SpringBootApplication (commented)
//ComponentScan(basePackages=“io.datajek.spring.basics.movierecommendersystem.lesson10”) (commented)
ComponentScan(includeFilters = @ComponentScan.Filter (type= FilterType.REGEX, pattern=“io.datajek.spring.basics.movierecommendersystem.lesson9.*”))

In this case : CollaborativeFilter bean found = false.
ContentBasedFilter bean found = True.

My question is why we are getting true for ContentBasedFilter bean in case 3 when //SpringBootApplication annotation is (commented) ,
but in case 1 we are getting false for both beans
when //SpringBootApplication annotation is (commented)
please explain when do we need to include SpringBootApplication and when not too.

According to me we should get true , true for case 1.