Spring Boot introduced a package under section Bean

  Spring Boot the environment, if there is a third party package third.jar, there are com.xxx.config directory, there are three in the directory com.xxx.config @Component class are annotated A, B, C, and now we need to get registered to Spring container A in the application, while B, C is not registered in. There are two methods:

  1. @ComponetScan using the Filter, like this: @ComponentScan (basePackageClasses = A.class, useDefaultFilters = false, includeFilters = Filter (type = FilterType.ASSIGNABLE_TYPE, classes = A.class)), described a scanning basePackageClasses = A.class A. pack class is located, is com.xxx.config, useDefaultFilters = false representation is @ Service, @ Componet, @ Configuration annotation of these classes can not be scanned registration, ype under includeFilters = FilterType.ASSIGNABLE_TYPE manually specify needed to be represented include class (there is a similar exclude), classes = A.class represents a is injected into the container. Overall, it is this: let om.xxx.config is to include the Spring container.
  2. Longer described above, it is a standard way, there is a relatively simple: in this way the above functions can be achieved by the Spring Boot @Import (A.class). But I used the first way point, the second in this way always feel a little strange.

Guess you like

Origin www.cnblogs.com/dreamroute/p/12194402.html