Annotations Cheat Sheet
Spring Boot and Web Annotations Spring Framework Annotations
Use annotations to configure your web application. Spring uses dependancy injection to configure and bind your T M @Primary - gives higher preference to a bean
appliation together. when there are multiple beans of the same type.
T @SpringBootApplication - uses @Configuration,
@EnableAutoConfiguration and @ComponentScan. T @Configuration - used to mark a class as a source of C F M @Required - shows that the setter method
the bean definitions. must be configured to be dependency-injected with a
T @EnableAutoConfiguration - make Spring guess the
value at configuration time.
configuration based on the classpath. T @ComponentScan - makes Spring scan the packages
configured with it for the @Configuration classes. C F M @Value - used to assign values into fields in
T @Controller - marks the class as web controller,
Spring-managed beans. It’s compatible with the
capable of handling the requests. T @Import - loads additional configuration. This one
constructor, setter, and field injection.
works even when you specify the beans in an XML file.
T @RestController - a convenience annotation of a
T M @DependsOn - makes Spring initialize other
@Controller and @ResponseBody. T @Component - turns the class into a Spring bean at
beans before the annotated one.
the auto-scan time.
M T @ResponseBody - makes Spring bind method's
T M @Lazy - makes beans to initialize lazily. @Lazy
return value to the web response body. T @Service - tells Spring that it's safe to manage
annotation may be used on any class directly or indirectly
@Components with more freedom than regular
M @RequestMapping - specify on the method in the annotated with @Component or on methods annotated
components.
controller, to map a HTTP request to the URL to this method. with @Bean.
C F M @Autowired - wires the application parts
P @RequestParam - bind HTTP parameters into T M @Scope - used to define the scope of a @Com-
together, on the fields, constructors, or methods in
method arguments. ponent class or a @Bean definition and can be either
a component.
singleton, prototype, request, session, globalSession, or
P @PathVariable - binds placeholder from the URI to custom scope.
M @Bean - specifies a returned bean to be managed by
the method parameter.
Spring context. The returned bean has the same name as
T @Profile - adds beans to the application only when
the factory method.
that profile is active.
M @Lookup - tells Spring to return an instance of the
method’s return type when we invoke it.
Legend: T - Class F - Field Annotation C - Constructor Annotation M - Method P - Parameter
www.jrebel.com