On a SpringSource blog entry, the following sentence references a stereotype.
Because
@Controller
is a specialization of Spring's@Component
Stereotype annotation, the class will automatically be detected by the Spring container as part of the container's component scanning process, creating a bean definition and allowing instances to be dependency injected like any other Spring-managed component.
What does this usage of the word stereotype reference? Is this a technical Spring term? Or is stereotype just used in a general sense?
The Spring stereotype @Component is parent stereotype. The other stereotypes i.e @Service , @Repository and @Controller are the specialization of @Component annotation. The @ComponentScan is used in java configuration and component-scan is used for auto component scanning in XML.
Stereotype annotations are markers for any class that fulfills a role within an application. This helps remove, or at least greatly reduce, the Spring XML configuration required for these components.
The JavaDoc says a bit about it.
Annotations denoting the roles of types or methods in the overall architecture (at a conceptual, rather than implementation, level).
The noun definition of stereotype
from Merriam-Webster says this:
something conforming to a fixed or general pattern; especially : a standardized mental picture that is held in common by members of a group and that represents an oversimplified opinion, prejudiced attitude, or uncritical judgment
It seems that it is for suggesting a role of particular class that is being annotated. This seems to make sense because it is often recommended that you annotate your Controller classes with @Controller
, Service classes with @Service
, and so on.
In addition to the obvious component-scanning functionality, Spring suggests that they make nice point-cut demarcations for your AOP needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With