본문 바로가기

emotional developer/detect-Java

[spring] basePackages vs basePackageClasses

http://stackoverflow.com/questions/24130166/componentscan-basepackageclasses-vs-componentscan-basepackages-to-register-a-sin



The full javadoc for that attribute reads

Type-safe alternative to basePackages() for specifying the packages to scan for annotated components. The package of each class specified will be scanned.

Consider creating a special no-op marker class or interface in each package that serves no purpose other than being referenced by this attribute.

By type-safe, you can't make any mistakes with the String value of the name of the package. If you specify an incorrect class, it will fail at compile time.

When you specify basePackageClasses, Spring will scan the package (and subpackages) of the classes you specify. This is a nice trick with no-op classes/interfaces like ControllersServices, etc. Put all your controllers in one package containing the Controllers class and specify your Controllers class in the basePackageClasses. Spring will pick them all up.

You still need to specify the filters.



basePackageClasses 는 컴파일시에 체크가능, 별도의 root 클래스가 있어야함.

basePackages 는 런타임시에 체크가능





반응형