What is a Spring "stereotype"?

chad picture chad · Feb 7, 2013 · Viewed 31k times · Source

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?

Answer

nicholas.hauschild picture nicholas.hauschild · Feb 7, 2013

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.