Below is source code of For Component Interface
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Component {
and for Spring Controller annotation is as below
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {
Why @Component is added in Controller annotation ? What is its purpose ? What if I remove this line ?
I am clear about below annotation types which are used to create custom annotations.
@Documented Whether to put the annotation in Javadocs
@Retention When the annotation is needed
@Target Places the annotation can go
@Inherited Whether subclasses get the annotation
@Controlleris a@Component. The@Componentis used as a meta-annotation here so that it can be picked-up using component-scanning. The@Controlleris a special component which will have some added functionality. If you remove the@Componentannotation component-scan will not detect it anymore. You can also create your own@Componentbased annotations.