Common usages of Spring Framework annotations and features
AOP and Instrumentation
Spring MVC - Controller
Annotation to indicate that the class is a controller class.
A convenience annotation that is itself annotated with
@ResponseBody. Used in controllers that will behave as RESTful resources.
Annotation to be used on methods in
@RestController classes. You can provide an URI to be served as RESTful service.
Annotation used to bind values present in views.
Annotation used to provide configurations.
Annotation that acts like a provider where you can define how the bean is instantiated when a injection of that type is requested. Instances of
@Bean annotated methods will act as singletons.
Properties Evaluation Sequence
java -Dproject.name=Test -jar app.jar
External properties/yml file
Internal properties/yml file
The default properties/yml files are application.properties and application.yml and they are located in
Spring Boot Initializer
Web service that allows the user to specify the project metadata and dependencies as well as download the initial structure.
A CLI tool that interacts with http://start.spring.io service to scaffold a new project.
Spring Tool Suit
Eclipse-based IDE that also interacts with http://start.spring.io to scaffold a new project.
Intellij also provides a way of creating a new project via http://start.spring.io.
Spring Boot - Auto Configuration
Only available if the Tomcat class is found in the classpath.
@ConditionalOnProperty(name = "tomcat.version", matchIfMissing = true)
Only available if the property
tomcat.version is set to true.
Auto configuration is just the combination of
@Conditional* annotations in order to correctly register beans.
Annotation used to inject an object that is already in the Application Context. It searches the instance by name. It also works on setter methods.
Annotation used to inject objects in many possible ways, such as: instance variable, constructor and methods. It does not rely on name as
@Resource, so, for multiple concrete implementations, the
@Qualifier annotation must be used with it.
Annotation used to distinguish between multiple concrete implementations. Used alongside with
@Autowired annotation that does not rely on name.
Annotation used when no name is provided telling Spring to inject an object of the annotated class first. Used along with
Generic stereotype annotation used to tell Spring to create an instance of the object in the Application Context. It's possible to define any name for the instance, the default is the class name as camel case.
Stereotype annotation for presentation layer.
Stereotype annotation for persistence layer.
Stereotype annotation for service layer.
Property to be set in application.properties in order to tell Spring what profiles are active.
Annotation used to define which profile can execute the annotated method.
Spring Boot - Basics
Initial annotation that comprises the following annotations:
Indicates that a class provides Spring Boot application
Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need.
Configures component scanning directives for use with
Most of the time you will need only to declare the