When spring scans a component, will it scan the component's parent class and interface? Is there a clear documentation?

such as the title.
such as the title.
such as the title.

Feb.28,2021

there is a very good example of setting the range of spring scanning
those who meet the following conditions will be scanned and a bean will be created

    The
  • class has @ Component comments
  • and the package name is included in the @ ComponentScan comment
  • or included in the @ ComponentScan.Filter scope

if the subclass meets the criteria, but the parent class is not included in the scan scope, the subclass will be created, but the parent class will not be created, because it does not meet the instanceof condition, that is, it cannot be said that the parent class is a subclass
if the parent class is created, the subclass has a @ Component annotation, but it is not within the specified Filter range, it will also be created because it meets the instanceof condition, because the subclass must be .

@ Component annotations have no inheritance relationship ( @ Inherited ), so you must have this annotation first if you want to be created.
or create your own inheritable annotated interface.

such as:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component 
@Inherited
public @interface BusinessService {
}

in addition, if it is spring boot, you can actually test and see the result http://ip:port/beans


.

ask and answer yourself. The answer to the question was found by tracking the source code the next day, and the result will give experience to future generations.
Why is there such a problem? it comes from the springcloud feign remote call scenario. Controller inherits api service, 's definition of service method, which is not defined in RequestMapping,controller, and spring can also scan and complete the mapping of request address and method. The strange part of this process is, The annotations defined in the interface are not inherited by the class, and the only way to identify them is to scan the parent class, but generally it seems that it has never been used in this way. In the articles on spring source code parsing, it is rarely mentioned that the scanning component will look for annotations in the parent class, trace the source code with problems, and find that the searchWithGetSemantics, semantic search method of such a class AnnotatedElementUtils, has been called repeatedly in the process of scanning the component.
`*

{@ code AnnotatedElementUtils} defines the public API for Spring's

is clearly answered by comments on what is meant by semantic search.
  • meta-annotation programming model with support for annotation attribute
  • overrides. If you do not need support for annotation attribute
  • overrides, consider using {@ link AnnotationUtils} instead. *

    Find semantics are much more exhaustive, providing

  • get semantics plus support for the following:

*

    • Searching on interfaces, if the annotated element is a class
    • Searching on superclasses, if the annotated element is a class
    • Resolving bridged methods, if the annotated element is a method
    • Searching on methods in interfaces, if the annotated element is a method
    • Searching on methods in superclasses, if the annotated element is a method
    `
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c1b31e-32798.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c1b31e-32798.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?