Common annotations of springboot / springcloud

Common annotations of springboot / springcloud

@Data: Annotated on the class, which includes @Getter, @Setter, @ToString, @EqualsAndHashCode, @RequiredArgsConstructor, etc .;

If the property is a final modified property, no setter method will be generated for the property .

@Getter: Annotations can be written on the class or on specific properties, providing getter methods for all properties or specific properties in the class;

@Setter: Annotations can be written on the class or specific properties, providing setter methods for all non-final modified properties or specific non-final modified properties
in the class ; @ToString: Annotations written on the class, Lombok will generate a toString () Method, by default, the class name and all attributes will be output (in the order of attribute definition), separated by commas;

@EqualsAndHashCode: By default, all non-static (non-static) and non-transient (non-transient) attributes are used to generate equals () and hasCode (), and some attributes can also be excluded through exclude annotations;

@NonNull: This annotation is used on properties or constructors. Lombok will generate a non-null declaration that can be used to verify parameters, which can help avoid null pointers;

@ Slf4j: The annotation is written on the class, and the log object is generated according to the actual log framework used by the user;

@ Log4j: Annotation is written on the class; provide a log4j log object with the property name log for the class

The meaning of @Primary tells the Spring IoC container that when multiple Beams of the same type are found, please use the ones marked as @Primary first

@Async means that it can be executed asynchronously, which means turning on multithreading. Do not define the modified function as static type, so that asynchronous calls will not take effect

@EnableAsync annotation means that it can be executed asynchronously, which means to start multithreading. Can be marked on methods and classes.
In order for @Async annotation to take effect, you need to configure @EnableAsync in the main program of Spring Boot

@GetMapping = @RequestMapping (method = RequestMethod.GET) abbreviation
@PostMapping = @RequestMapping (method = RequestMethod.POST) abbreviation
@PutMapping = @RequestMapping (method = RequestMethod.PUT) @PostMapping and @PutMapping are equivalent, both are Used to submit information to the server
@DeleteMapping = @RequestMapping (method = RequestMethod.DELETE), the role: corresponding to delete, indicating that it is a delete URL mapping
@PatchMapping

Spring Cloud's commons module provides a @LoadBalanced annotation, which is convenient for us to add a LoadBalancerClient to RestTemplate to achieve client load balancing.
Through the source code, it can be found that this is a markup annotation, and we can achieve the load balancing function of the client through the ribbon.
@Cleanup close the stream
@Synchronized: Object synchronization
@SneakyThrows: Throw an exception
@ConfigurationProperties (prefix = "upload") Automatically encapsulate similar configuration information into entity classes: You can make the values ​​in the properties file correspond to the properties in the class;
There are two ways to use: 1. Use the annotation on the class 2. Use the annotation (@bean) on the factory method.
Note: In addition to using this annotation to read property file values ​​in springBoot, you can also use @Value annotation.

Published 67 original articles · Liked12 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/m0_37635053/article/details/103910279