Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Spring "stereotype"?

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?

like image 950
chad Avatar asked Feb 07 '13 16:02

chad


People also ask

Which of these are stereotypes and will be discovered by component scanning in Spring?

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.

What is meant by stereotype annotation?

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.


1 Answers

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.

like image 152
nicholas.hauschild Avatar answered Oct 01 '22 21:10

nicholas.hauschild