Spring framework common annotations

1. Spring common annotations


annotation illustrate
@Component 、@Controller、@Service、@Repository is used on classes to declare Beans.
The @Component annotation is equivalent to the bean tag in the spring core configuration file. @Controller (control layer), @Service (business layer), @Repository (data access) are all @Component derived annotations. , also declares beans.
@Autowried、@Resource is used on fields for dependency injection.
@Autowried injects dependencies by type by default. If there are multiple beans of the same type when used, an error will be reported (the only bean exception). Solution: Use @Qualifier in combination with @Autowired to use it according to the specified Bean name for dependency injection.
@Resource, it is not provided by spring. By default, it is searched according to the field name (matching beans with the same name). If it is found, it is directly assembled. If the resource cannot be found according to the field name, it will be searched according to the type and Assembly;
@Scope The scope of the bean, such as Singleton (default), multiple prototypes.
@Configuration Specifies that the current class is a spring configuration class, and annotations will be loaded from this class when the container is created.
@ComponentScan Used to specify the packages to be scanned by Spring when initializing the container.
@Bean When used on a method, the return value of the current method will be placed in the Spring container. (Generally used in combination with @Configuration annotation to define third-party beans)
@Import Classes imported using @Import will be loaded into the IOC container by Spring
@Aspect、@Before、@After、@Around、@Pointcut For aspect programming (AOP)
@Aspect (define aspects), @Before (pre-notification), @After (post-notification), @Around (surround notification) , @Pointcut (define pointcut expression)

2. SpringMVC common annotations

annotation illustrate
@RequestMapping Used to map request paths, which can be defined on classes and methods. Used on classes to represent parent paths. @RequestMapping derived annotations include: @GetMapping, @PostMapping, PutMapping, @DeletetMapping
@RequestBody The annotation implements receiving the json data of the http request, and converts the json into a Java object as input parameters.
@RequestParam Specify the name of the request parameter
@PathVariable Get the parameters from the request path, such as /user/{id}, and then pass it to the formal parameters of the method through the @PathVariable annotation
@ResponseBody Convert the return value of the request processing method into a json object and respond to the client
@RequestHeader Get the specified request header data
@RestController Used to create a controller class that only returns data but not pages, @RestController=@Controller +@ResponseBody.

3. SpringBoot common annotations

annotation illustrate
@SpringBootConfiguration Declare that the current class is a springboot configuration class and is a @Configuration derived annotation.
@EnableAutoConfiguration Turn on the automatic configuration function, or turn off an automatic configuration option.
@ComponentScan spring component scan
@Conditional Decide whether to create a bean or perform specific configuration based on specific conditions
@SpringBootApplication: Used to identify the main class, indicating that this class is the entry point of the SpringBoot application.

Guess you like

Origin blog.csdn.net/qq_46921028/article/details/131624329