0% found this document useful (0 votes)
173 views5 pages

Spring Annotations

Download as docx, pdf, or txt
0% found this document useful (0 votes)
173 views5 pages

Spring Annotations

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

Spring Annotations Reference

ANNOTATIONS DESCRIPTION

@Component annotation is the generalized form considered as a


@Component,
candidate for auto-detection when using annotation-based
@Repository, and
configuration and classpath scanning. It extended to more specific
@Service
forms such as @Controller, @Repository, and @Service.

The XML files define string bean dependencies, and the same can be

automatically detected by the Spring container by using the


@Autowired
@Autowired annotation. This would eliminate the use of XML

configurations.

There may be scenarios when you create more than one bean of the

same type and want to wire only one of them with a property. Control
@Qualifier
this using @Qualifier annotation along with

the @Autowired annotation.

@Required annotation applies to bean property setter methods and


@Required
enforces required properties

Difference between This tutorial explains the difference between these three annotations
@Resource, @Autowired, @Resource, @Autowired and @Inject used for injecting the

and @Inject objects.

@Inject and @Named annotations are JSR-330 annotations were

@Inject and @Named introduced in Spring 3 as an alternative for the spring annotations

@Autowired and @Component.

This tutorial explains the JSR-250 annotations that Spring 2.5


@Resource,
introduces, which
@PostConstruct, and
include @Resource, @PostConstruct, and @PreDestroy annotatio
@PreDestroy
ns.

@RestController annotation is inherited from the

@Controller annotation. This is the special version of

@RestController @Controller annotation for implementing the RESTful Web

Services. @RestController was added as part of the Spring

4 release.

@RequestHeader annotation for facilitating us to get the header


@RequestHeader
details easily in our controller class. This annotation would bind the

header details with the method arguments, and it can be used inside
the methods.

@ControllerAdvice annotation used for defining the exception

handler with specific exception details for each method. This


@ControllerAdvice
component will handle any exception thrown on any part of the

application.

@ModelAttribute annotation can be used as the method arguments

or before the method declaration. The primary objective of this


@ModelAttribute
annotation to bind the request parameters or form fields to a model

object.

This tutorial explains one of the new features introduced in spring


@Conditional
4, conditional annotation type.

This spring data series tutorial explains @query annotation and how
@Query
to create a custom query using the @query annotation.

This tutorial explains how to enable profiles in your spring


@Profile
application for different environments.
Instead of using the XML files, we can use plain Java classes to

annotate the configurations by using the

@Configuration @Configuration annotation. If you annotate a class with

@Configuration, it indicates that the class defines the beans using

the @Bean annotation.

We have to use @PathVariable for accepting the customized or


@PathVariable
more dynamic parameters in the request paths.

@Controller,

@RequestMapping, This tutorial explains some of the key annotations that are related to

@RequestParam, Spring MVC applications @Controller, @RequestMapping,

@SessionAttributes, and @RequestParam, @SessionAttributes, and @InitBinder

@InitBinder

Difference between
This tutorial explains the difference between the two annotations
@RequestParam and
@RequestParam and @PathVariable.
@PathVariable

You can use @RequestMapping annotation for mapping web


@RequestMapping
requests to particular handler classes or handler methods.
This tutorial shows how to load the properties file values using the
@Value
@Value annotation.

@Import is the annotation used for consolidating all the

@Import configurations defined in various configuration files

using @Configuration annotation.

Use annotation @Transactional to define a particular method that


@Transactional
should be within a transaction.

This is annotation is the heart of spring boot application.

@SpringBootApplication @SpringBootApplication indicates that it is the entry point for the

spring boot application.

This example demonstrates how to use the


@EnableAutoConfiguratio
@EnableAutoConfiguration annotations for auto-configuring the
n
spring boot applications.

@EnableCaching annotation is the annotation-driven cache

@EnableCaching management feature in the spring framework. This annotation added

to the spring in version 3.1.

You might also like