This is the 29th day of my participation in the August Wenwen Challenge.More challenges in August

preface

Annotations themselves are not functional, just like XML. Annotations and XML are a type of metadata, and metadata is the data that interprets the data, known as configuration.

Commonly used annotations

@Component

Indicates that an annotated class is a “component” that becomes a Spring-managed Bean. These classes are considered candidates for automatic detection when annotation-based configuration and classpath scanning are used. The @Component is also a meta-annotation.

@Service

Composite annotations (combined with the @Component annotation) are applied to the Service layer (business logic layer).

@Repository

Composite annotations (incorporating the @Component annotation) are applied to the DAO layer (data access layer).

@Controller

Composed annotations (composed with @Component annotations) applied to the MVC layer (control layer),DispatcherServlet automatically scans for classes annotated with this annotation and maps web requests to methods annotated with @RequestMapping.

@RequestMapping

Used to map Web requests, including access paths and parameters. (class or method)

@ResponseBody

Support for putting return values in response instead of a page, and usually the user returns JSON data. (next to return value or on method)

@RequestBody

Allows the parameters of the request to be in the body of the request, instead of being concatenated directly after the address. (Placed before parameters)

@PathVariable

RequestMapping(” /hello/{name} “) is used to receive path parameters, for example, the path declared by @requestMapping (” /hello/{name} “). This value can be obtained by putting annotations in the parameter, and is usually implemented as a Restful interface method.

@RestController

This annotation is a combined annotation, which is the equivalent of @Controller and @ResponseBody, and the annotation on the class means that all of the methods on this Controller are going to have @ResponseBody by default.

@ExceptionHandler

Handle exceptions in the controller globally.

@ModelAttribute

@controllerAdvice allows @requestMapping globally to get the key/value pairs set here.

@Autowired

Tools provided by Spring (automatically injected by Spring’s dependency injection tools (BeanPostProcessor, BeanFactoryPostProcessor).

@Configuration

Declare the current class to be a configuration class (equivalent to a Spring configuration XML file) (on class).

@Bean

Annotation on a method that declares the return value of the current method to be a Bean. You can define init() and destroy() methods in the corresponding class of the returned Bean, and then define them in the @bean (initMethod= “init”,destroyMethod= “destroy”), init after construction, and destroy before destruction. (Methodological)

@ComponentScan

Automatically scans and registers all classes that use @service, @Component, @Controller, and @repository in the specified package.

@Aspect

Declare an aspect (classwise) that defines advice using @after, @before, and @around, taking the interception rule (pointcut) directly as an argument.

@after: execute After method execution.

@before: Execute Before method execution (method).

@around: Before and after method execution (method).

Use the @enableAspectJAutoProxy annotation in a Java configuration class to turn on Spring support for AspectJ proxies (class-wide).

@Scope

Defines what mode we use to create beans (in this case, @beans). The setting types include:

Singleton (Singleton, one bean instance in a Spring container, default mode), Prototype (new bean per call), Request (In web project, Create a bean for each HTTP Request), Session (create a bean for each HTTP Session in a Web project), GlobalSession (create a bean instance for each Global HTTP Session).

@PostConstruct

The annotation is on the method, which is executed after the constructor completes execution.

@PreDestory

Annotated on a method that is executed before the object is destroyed.

@Value

Often used with the Sping EL expression language to inject ordinary characters, system properties, expression results, properties of other beans, file content, url request content, configuration file property values, etc.

@EnableAsync

This annotation is used to enable support for asynchronous tasks in the configuration class, the narrative AsyncConfigurer interface. (class)

@Async

The bean method that actually executes uses this annotation to declare that it is an asynchronous task (all methods on a method or class will be asynchronous, requiring @enableAsync to enable asynchronous tasks)

@EnableScheduling

Used on configuration classes to enable support for scheduled tasks. (class)

@Scheduled

To declare that this is a task, including cron,fixDelay,fixRate, etc. (In terms of methods, you need to enable the support for scheduled tasks first)

@enable * Comments

These comments are mainly used to turn on support for XXX. @enableAspectJAutoProxy Enables automatic AspectJ proxy support.

@enableAsync: enable support for asynchronous methods.

EnableScheduling: Enable support for scheduled tasks.

@enablewebmvc: EnableWebMvc configuration support.

@ EnableConfigurationProperties: open support for @ ConfigurationProperties annotation configuration Bean.

EnableJpaRepositories: Enable support for SpringData JPA Repository.

@ EnableTransactionManagement: open annotation type transaction support.

@ EnableTransactionManagement: open annotation type transaction support.

@enablecaching: Enable annotated caching support.