Spring Learning Notes 01_ Basics

Source: Internet
Author: User

1.Spring architecture?

Mainly divided into 5 major modules:

(1) data access and integration : JDBC, ORM, OXM, JMS, transaction management.

Spring stands at the abstract level of DAO, and sets up a set of anomaly system for DAO layer unification, and transforms the anomaly anomaly of various access data into non-check anomaly, which provides the foundation for the integration of various long-layer frameworks.

Second, spring provides a thin-layer encapsulation of various database access technologies through templating technology, which hides the modeled code and simplifies the code for database access.

In this way, Spring creates a unified DAO layer that is not related to data form access technology, and with AOP technology, Spring provides the functionality of declarative transactions.

(2) Web and remote operations : MVC, Web Service, Portlet

The module is built on the application Context module and provides a variety of tools for Web applications. If the spring container is initialized with a listener or servlet, the spring container is registered in the Web container.

Second, the module also provides a variety of web-oriented features, such as transparent file upload, Velocity, Freemarker, XSLT support.

In addition, spring can integrate MVC frameworks such as Struts2, WebWork, and so on.

(3) Test framework

(4) AOP: Spring AOP, aspects

AOP is the idea of cross-cutting logic programming, and it opens up the thought of thinking problems.

(5) IoC: Bean, Context, expression statement

The spring core module implements the functions of the IOC, which detach the dependencies between classes and classes from the code, and describe the dependencies in a configured way, with the IOC container responsible for creating, splicing, managing, acquiring, and so on.

The Beanfactory interface is the core interface of the spring framework, which implements many of the core functions of the container.

The context module builds and core modules, expands the function of beanfactory, adds il8n internationalization, bean Lifecycle control, framework event System, resource loading transparency and many other functions. The module also provides support for many enterprise-class services such as mail services, task scheduling, jndi positioning, EJB integration, remote access, and so on. ApplicationContext is the core interface of the context.

Expression language is an extension of the Unified Expression language (Unified EL), which is used to query and manage runtime objects, support setting and getting object properties, calling object methods, manipulating arrays, collections, and so on. It also provides functions such as logical expression operation, variable definition, and so on, which can easily interact with the SPRINGIOC container through the expression string.

2. Understanding IOC (inversion of control, inversion of controls)

Understanding di (Dependency Injection): Dependency injection, whether it is the action object of the control layer, the service object of the business layer, or the DAO object of the persistence layer, can be coordinated and run organically under Spring's management. Spring organizes the objects of each layer together loosely, and the action object does not care about the specific implementation of the service object, and the invocation of each layer object is completely interface-oriented. When the system needs refactoring, the amount of rewriting of the code is greatly reduced.

This is referred to as dependency injection because the work of the callee instance is usually done by the spring container and then injected into the caller. In the process of running the program, if you need a brother Ayung an object assistance, you do not need to create the callee in the code, but instead rely on the external injection. Spring's dependency injection has virtually no requirement for callers and callers to fully support the management of dependency between Pojo.

DI (Dependency injection) and IOC (inversion of control) are the same concept.

IoC: When a role (a Java instance, the caller) needs the assistance of another role (another Java instance, the callee), in the traditional programming process, it is generally the caller who creates the instance of the callee. In spring, the creation of the callee's work is no longer done by the consumer, so it becomes a control reversal. That is, all components are passive, and all components and calls are owned by the container and managed by the container.

3.Spring Injection

Spring injection completes the assignment of variables when the spring container is started to load the bean.

Two common ways to inject: Set injection and construct injection.

Scope of 4.Bean

Singleton: Singleton, refers to a bean container value exists in one copy.

Prototype: Each request (per use) creates a new instance, and the Destroy method does not take effect.

Request: Each HTTP request creates an instance and is valid only within the current request

Session: Ditto, each HTTP request is created, the current session is valid

Global session: Portlet-based text is valid (the Portlet defines the global session), if it is in the Web, the same session.

Life cycle of 5.Bean

(1). Define

(2). Initialize

Implement Org-springframework.beans.factory.initializingbean interface, overwrite Afterpropertyset method

Configure Init-method

(3). Use

(4). Destruction

Implement the Org-springframework.beans.factory.disablebean interface, overriding the Destroy method.

Configure Destory-method

The life cycle of beans in 6.Spring

(1) Singleton scope

When the scope of a bean is set to Singleton, only a shared bean instance exists in the spring IOC container, and all requests to the bean are returned to the same instance of the bean as long as the ID matches the bean definition. When a bean definition is set to singleton scope, the Spring IOC container only creates a unique instance of the bean. The singleton is stored in a singleton cache, and all subsequent requests and references to the bean are returned to the object instance of the flower village.

(2). Prototype scope

Prototype-scoped beans, each request (injected into another bean, or programmatically invoking the container's Getbean () method) results in a new bean instance. Equivalent to a new operation. For prototype-scoped beans, it is important to note that spring cannot be responsible for the entire life cycle of a prototype bean, and that the container will marry the client after initializing, configuring, or assembling a prototype instance, and then no longer.

Spring Learning Notes 01_ Basics

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.