Talking about @RequiredArgsConstructor annotation

generate a constructor with required parameters

This matter must import the lombok package when using lombok

<dependency>

    <groupId>org.projectlombok</groupId>

     <artifactId>lombok</artifactId>

      <version>1.18.12</version>

</dependency>

Note:
1. Variables must be declared as final

2. According to the constructor injection, it is equivalent to when the container calls the class constructor with a set of parameters, the constructor-based DI is completed, and each parameter represents a dependency on other classes. Assign values ​​to properties based on the construction method, and the container injects dependencies by calling the construction method of the class

It can be used directly on the class name when we need to inject beans. Replaces Autowritten annotations
 

Supongo que te gusta

Origin blog.csdn.net/meihuacike/article/details/120328067
Recomendado
Clasificación