Posts

Showing posts with the label Spring auto scan component

About Spring @Component, @Repository, @Service and @Controller Annotations.

Spring @Component , @Service , @Repository and @Controller annotations are used for automatic bean detection using classpath scan in Spring framework. These four  annotations are same logically. Differences between @Component, @Repository, @Controller and @Service: @Component  This is a general-purpose stereotype annotation(auto scan) indicating that the class is a spring component. @Component annotation picks them up and registers their following classes as beans, just as if they were annotated with @Component . @Repository This is special type of @Component annotation.   This is to indicate that the class defines a data repository.  @Controller This is special type of @Component annotation. The @Controller annotation indicates that a particular class serves the role of a controller. The @Controller annotation acts as a stereotype for the annotated class, indicating its role.  What’s special about @Controller? We cannot...