Spring boot reading notes


The download address of the Maven central library for reading and writing: ( http://mvnrepository.com/ )

Knowledge points:
1. @Configuration declares that the current class is a configuration class
2. @ComponentScan automatically scans all classes using @Service, @Component, @Repository and @Controller under the package name, and registers them as Beans.
3. AnnotationConfigApplicationContext as the Spring container
4. Use the @Bean annotation to declare that the return value of the current method is a Bean, and the name of the Bean is the method name.
5. A prototype-scoped bean will cause a new bean instance to be created every time the bean is requested (injecting it into another bean, or calling the container's getBean() method programmatically).
As a rule of thumb, you should use prototype scope for stateful beans and singleton scope for stateless beans.
6. Bean initialization and destruction:
Java configuration method: use @Bean's initMethod and destroyMethod (equivalent to xml configuration init-method and destroy-method)
Annotation method: use JSR-250's @PostConstruct and @PreDestroy
7. Spring's Events:
custom events, inherit ApplicationEvent
to define event listeners, inherit ApplicationListener
to use the container to publish events
8. Spring implements multithreading through TaskExecutor. Using ThreadPoolTaskExecutor can implement a TaskExecutor with an opportunity thread pool.
Usage: Enable support for asynchronous tasks through @EnableAsync in the configuration class, and declare an asynchronous task by using the @Async annotation in the actual execution bean method.
9. Scheduled tasks: configure @EnableScheduling in the configuration class to enable support for scheduled tasks, and then support multiple types of scheduled tasks through @Scheduled, including cron, fixDelay, fixRate, etc.
10. Meta-annotations: can be annotated to other annotations Annotation;
combined annotation: Annotated annotation;
such as: @WiselyConfiguration combined annotation replaces @Configuration and @ComponentScan
11. Spring MVC provides a DispatcherServlet to develop Web applications. In Servlet2.5 and below, you only need to configure the elements under web.xml <servlet>. In this section, Servlet3.0 + no web.xml will be used. Implementing the WebApplicationInitializer interface in Spring MVC can be equivalent to web.xml Configuration.
12. The runtime code will automatically compile our page (.jsp file) to /WEB-INF/classes/views/.
13. The custom configuration of Spring MVC requires our configuration class to inherit a WebMvcConfigurerAdapter class, and use the @EnableWebMvc annotation in this class to enable configuration support for Spring MVC.
14. The methods of classes annotated with @Controller can be annotated with @ExceptionHandler, @InitBinder, @ModelAttribute:
@ExceptionHandler: used to globally handle exceptions in the controller
@InitBinder: used to set WebDataBinder, WebDataBinder is used to automatically bind Set the request parameters to the Model the day before yesterday
@ModelAttribute: used to bind the key value to the Model
15. Spring MVC uploads files by configuring a MultipartResolver. In Spring's controller, files are received through MultipartFile file, and multiple file uploads are received through MultipartFile[] files.
16.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325953831&siteId=291194637