In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to configure the life cycle of Spring Bean". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Scope of Bean
Of the five scopes, request, session and global session are only used in web-based applications (regardless of what web application framework you use), and can only be used in web-based Spring ApplicationContext environments.
When the scope of a bean is Singleton, there is only one shared bean instance in the Spring IoC container, and all requests for bean will only return the same instance of bean as long as the id matches the bean definition. Singleton is a singleton type, that is, a bean object is automatically created when the container is created. It exists regardless of whether you use it or not, and the object you get each time is the same object. Note that the Singleton scope is the default scope in Spring.
When the scope of a bean is Prototype, it means that a bean definition corresponds to multiple object instances. The bean of the Prototype scope causes a new bean instance to be created each time the bean is requested (injected into another bean, or programmatically called the container's getBean () method). Prototype is a prototype type that is not instantiated when we create the container, but only creates an object when we get the bean, and the object we get each time is not the same object. As a rule of thumb, you should use prototype scope for stateful bean and singleton scope for stateless bean. Define bean as prototype in XML, which can be configured as follows:
/ / or
When the scope of a bean is Request, it means that in a HTTP request, a bean definition corresponds to an instance; that is, each HTTP request will have its own bean instance, which is created based on a bean definition. This scope is valid only in web-based Spring ApplicationContext cases. Consider the following bean definition:
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.