Spring Framework Learning Notes (i)--Basic __java

Source: Internet
Author: User
1. What is Spring framework

Spring is a container framework that is used to configure various beans and maintain relationships between the various beans. 2. The advantage of using the Spring Framework is a lightweight and minimal intrusive framework based on Pojo. The spring framework strives to avoid confusing your application code with its own APIs, minimizing intrusion. It does not force you to implement the interface of the spring specification or to inherit the class of the spring specification to inspire Pojo potential. High cohesion low coupling is achieved by dependency injection and interface oriented. The spring framework is a large factory that can maintain all object creation and dependencies to spring management. When you modify a business, you do not need to modify a lot of your Java code, but through a small number of configuration to implement the modification. Reduces the effect of "far-reaching". Based on cutting and template programming, reduce the amount of code and improve the reusability of code. Spring is designed to eliminate boilerplate code through template encapsulation so that similar tasks are not repeated over and over again using the same Code 3.Spring framework to bring us what

This is done when you do not use the Spring framework: Create an instance object set related properties call the corresponding object method

When using the spring framework, this is done by creating a spring IOC container object to get the bean instance from the IOC container to invoke the corresponding object method

To sum up, the spring framework helps us go to the new object and set the corresponding attributes, just write the spring configuration file and let the framework do the rest of the work for us.

4. The process of using the Spring Framework introduces the spring's development package (jar package) to create spring's core file Applicationcontext.xml configuration bean (the role of bean element: When we spring load, Spring automatically creates a bean) uses Spring Framework 5 in Test.java . Use context containers and beanfactory

If the context container is used, the configured bean, if it is Singlton, is instantiated regardless of whether it is not used (benefits: can be preloaded; bad: Memory consumed)

If you use Beanfactory, when you instantiate the object, the configured bean is not instantiated immediately, and is instantiated when you use it (benefits: Save memory; bad: Slow)

Experience: In general, use the context container applicationcontext. 6. Three kinds of Get ApplicationContext object reference method

Classpathxmlapplicationcontext--> through class path

Filesystemxmlapplicationcontext--> via file path

Xmlwebapplicationcontext--> is instantiated through the life cycle of the Web system 7.bean (but when we load the XML file), our bean is instantiated into memory call set method settings property if you implement be An name is concerned about the interface, you can get the ID number by Setbeanname If you implement the Bean factory attention interface, you can get beanfactory if you implement the Applicationcontextaware interface, call the method If the bean is associated with a back processor, the Objectpostprocessbeforeinitialization method is automatically invoked if you implement the Initializingbean interface, you will invoke the Afterpropertisset If you are <bean Init-method = ' init '/>, you can define your own initialization method in the bean if the bean is associated with a back processor, The Objectpostprocessafterinitialization method is automatically invoked using our bean container to close can invoke the method by implementing the Disposablebean interface destroy can be <bean Destroy-methon = ' fun1 '/> Call custom Destroy method

Summary: Generally not all use, generally will be: 1,2,6,10,9,11 8.Spring Automatic Assembly has four kinds of

ByName: In the IOC container, look for a bean that corresponds to the same ID as the property name in the Bean, and if no matching bean is found, the property is not successfully assembled Bytype: Look for beans of the same type in the IOC container, if no matching beans are found, No assembly succeeds; If multiple matching beans are found, an exception is thrown constructor: in the IOC container look for one or more beans that are consistent with the constructor parameters in the bean, and throw an exception autodetect if there is an indeterminate bean: automatic mode, First you will try to use constructor to come from the dynamic assembly and then use the Bytype method

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.