Friday, January 3, 2020

Spring Annotation Reference

Spring Annotations Reference

ANNOTATIONSDESCRIPTION
@Component, @Repository, and @Service@Component annotation is the generalized form considered as a candidate for auto-detection when using annotation-based configuration and classpath scanning. It extended to more specific forms such as @Controller, @Repository, and @Service.
@AutowiredThe XML files define string bean dependencies, and the same can be automatically detected by the Spring container by using the @Autowired annotation. This would eliminate the use of XML configurations.
@QualifierThere 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 this using @Qualifier annotation along with the @Autowired annotation.
@Required@Required annotation applies to bean property setter methods and enforces required properties
Difference between @Resource, @Autowired, and @InjectThis tutorial explains the difference between these three annotations @Resource, @Autowired and @Inject used for injecting the objects.
@Inject and @Named@Inject and @Named annotations are JSR-330 annotations were introduced in Spring 3 as an alternative for the spring annotations @Autowired and @Component.
@Resource, @PostConstruct, and @PreDestroyThis tutorial explains the JSR-250 annotations that Spring 2.5 introduces, which include @Resource@PostConstruct, and @PreDestroy annotations.
@RestController@RestController annotation is inherited from the @Controller annotation. This is the special version of @Controller annotation for implementing the RESTful Web Services. @RestController was added as part of the Spring 4 release.
@RequestHeader@RequestHeader annotation for facilitating us to get the header 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@ControllerAdvice annotation used for defining the exception handler with specific exception details for each method. This component will handle any exception thrown on any part of the application.
@ModelAttribute@ModelAttribute annotation can be used as the method arguments or before the method declaration. The primary objective of this annotation to bind the request parameters or form fields to a model object.
@ConditionalThis tutorial explains one of the new features introduced in spring 4conditional annotation type.
@QueryThis spring data series tutorial explains @query annotation and how to create a custom query using the @query annotation.
@ProfileThis tutorial explains how to enable profiles in your spring application for different environments.
@ConfigurationInstead of using the XML files, we can use plain Java classes to annotate the configurations by using the @Configuration annotation. If you annotate a class with @Configuration, it indicates that the class defines the beans using the @Bean annotation.
@PathVariableWe have to use @PathVariable for accepting the customized or more dynamic parameters in the request paths.
@Controller, @RequestMapping, @RequestParam, @SessionAttributes, and @InitBinderThis tutorial explains some of the key annotations that are related to Spring MVC applications @Controller, @RequestMapping, @RequestParam, @SessionAttributes, and @InitBinder
Difference between @RequestParam and @PathVariableThis tutorial explains the difference between the two annotations @RequestParam and @PathVariable.
@RequestMappingYou can use @RequestMapping annotation for mapping web requests to particular handler classes or handler methods.
@Value This tutorial shows how to load the properties file values using the @Value annotation.
@Import@Import is the annotation used for consolidating all the configurations defined in various configuration files using @Configuration annotation.
@TransactionalUse annotation @Transactional to define a particular method that should be within a transaction.
@SpringBootApplicationThis is annotation is the heart of spring boot application. @SpringBootApplication indicates that it is the entry point for the spring boot application.
@EnableAutoConfigurationThis example demonstrates how to use the @EnableAutoConfiguration annotations for auto-configuring the spring boot applications.
@EnableCaching@EnableCaching annotation is the annotation-driven cache management feature in the spring framework. This annotation added to the spring in version 3.1.

No comments:

Post a Comment