Understanding Ioc containers based on the nutz framework and the ioc framework of the nutz framework

Source: Internet
Author: User

Understanding Ioc containers based on the nutz framework and the ioc framework of the nutz framework
In the same way, we start with the problem to verify and understand what Ioc containers have done: 1. There are several ways to obtain information that requires container management beans?

The first is to configure the file in json format, such:

Type 2: Use annotation @ IocBean

Third: use xml .......
2. How can we select so many methods?
Our actual production environment usage is: the general dependency is fixed and remains unchanged during running. We use annotations, write the relationships that may change to the configuration file. For example, we use annotations for services between layers in the project,

Put database configurations in the configuration file,

3. How does the ioc container determine which beans need to be managed:

Q: a. How does one know which files are configured with beans that need to be managed by containers, and what classes of @ IocBean annotations need to be scanned ?? Nutz provides an annotation (@ IocBy) specifically used to specify which files and annotations to scan on the main module class.

You can know that the bean loader configured in json mode goes to webconfig/and scans in two paths in Linux. The bean loader configured in Annotation mode will scan the classes in the package starting with com. uxuexi. B. How does it scan jar packages other than this project (generally, it is created by itself and will not scan third parties? You can manually scan the bean managed by the container to the container before the ioc container of nutz is loaded when the project is started.4. When will these beans managed by containers be created?

When the service is started, nutz loads all classes annotated by @ IocBean and class information configured in the json format file into a map.

The map enclosed above. The key is the class name by default. The IocObject class mainly remembers the information of this class:

That is to say, when the server is started, nutz only scans annotations and files and stores the bean information to be managed by the container in a centralized place without actually creating the bean instances.5. When will the container create a real bean instance ??

There are two situations: 1. First, you need to obtain the bean instance in the container when the service starts. You can obtain the container manually.

2. The second type is the Module class mapped to the first http request. nutz will help you retrieve it from the ioc container.

6. What Ioc injection types are provided ??

Constructor injection:

Property injection:

7. When will the ioc container be destroyed ???

Nutz destroys the ioc container when the web Container stops running the destroy method of the Filter,

Methods In the NutzLoading class:

It is to clear the stored map in the cache.

 



 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.