In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the scope of the objects in the IOC container in the Spring framework? aiming at this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Singleton
There is only one instance in the IOC container, that is, objects created through the singleton scope are singletons.
The memory addresses of the two objects are the same, which indicates that the current object is indeed a singleton object.
Prototype
The first time an object is fetched from an IOC container, a new object is returned.
Request
Each HTTP request creates a new object, which is automatically destroyed when the request ends. This scope is intended for use in Web environments only.
Session
The same HTTP Session shares an object, different HTTP Session uses different objects, and when the Session ends, the object is destroyed. This scope is also intended for use in Web environments only.
GlobalSession
The same global Session shares an object, and the scope is only for use in the Web environment.
Delayed loading
We know that when we start the IOC container using the ApplicationContext interface, all singleton-scoped objects are automatically instantiated, unlike BeanFactory. Although doing this can be time-consuming when the IOC container starts, it also has the advantage of doing so. That is, the initialized object will be stored in the cache of the IOC container, so that when we use the object, we do not have to instantiate the object, thus improving the efficiency of the program. Another benefit is that it can help us find the problem early. If there is something wrong with the object we configure, it will throw an exception directly in the startup phase, not in the running phase of the program. Of course, each approach has its advantages and disadvantages, and if we don't want to instantiate the object at startup, we can directly delay the instantiation of our object with the lazy-init property provided to us by spring. That is, when you set the lazy-init property value to true and then start the IOC container through the ApplicationContext interface, the current object is not instantiated at startup, but is instantiated at run time.
This is the answer to the question about what the scope of objects in the IOC container in the Spring framework is. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.