In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what design patterns are there in spring". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what design patterns are in spring.
I. Strategy model
The algorithm or behavior is encapsulated into classes, and then different algorithms are implemented into different subclasses to achieve the effect of flexible call. The algorithm is encapsulated in the method and provides a consistent interface.
1. In the bean definition reader (BeanDefinitionReader), the resource loader (ResourceLoader) and the bean name generator (BeanNameGenerator) use the policy mode.
Then, ClassPathXmlApplicationContext and FileSystemXmlApplicationContext (overriding the method Resource getResourceByPath (String path)) are descendant classes of DefaultResource, representing two strategies for loading xml files: classpath and system path
II. Adapter mode
Https://blog.csdn.net/w1033162186/article/details/50635348
In the DispatcherServlet doDispatch method, the method that triggers the interface through the handle method of the handler object of HandlerAdapter. HandlerAdapter is an adapter, and its subclasses include SimpleControllerHandlerAdapter, SimpleServletHandlerAdapter, RequestMappingHandlerAdapter and so on. Controller subclass objects, Servlet objects and RequestMapping modified methods are encapsulated into HandlerAdapter objects to facilitate unified call.
Why use adaptation mode: you can see that different types of processors (broad concept Controller, HttpRequestHandler,Servlet, etc.) have multiple implementations, so the invocation mode is uncertain. If you need to call the Controller method directly, you have to constantly use if else to determine which subclass it is when you need to call it. This violates the principle of opening and closing.
Third, agency mode
AOP is implemented in proxy mode, including JDK dynamic proxy (which needs to implement the interface) and CGLib proxy (directly adding code to bytecode).
IV. Singleton model
Scope in Spring is the bean of singleton, and singleton mode is used. When getting, the double judgment locking mechanism is used.
GetSingleton RequestMappingHandlerAdapter of AbstractBeanFactory
V. Factory model
In aop, the creation of the agent uses the factory mode
Thank you for your reading, the above is the content of "what are the design patterns in spring". After the study of this article, I believe you have a deeper understanding of what design patterns are in spring, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.