Spring Framework Learning (1) Spring Introduction

Source: Internet
Author: User
Tags aop error handling to domain

Content from: Introduction to Spring Framework

Spring is an open source framework that is created to address the complexities of enterprise application development. One of the main advantages of the framework is its layered architecture , which allows you to choose which components to use while providing an integrated framework for Java EE application development.

Spring Framework

The Spring framework is a layered architecture consisting of 7 well-defined modules. The Spring module is built on top of the core container, and the core container defines how the beans are created, configured, and managed.

Each module (or component) that makes up the Spring framework can exist separately or be implemented in conjunction with one or more other modules. The functions of each module are as follows:

  • Core Container : The core container provides the basic functionality of the Spring framework. The main component of the core container is BeanFactory that it is the implementation of the factory pattern. BeanFactoryUse the inversion of Control (IOC) pattern to separate the application's configuration and dependency specifications from the actual application code.
  • Spring Context : The spring context is a configuration file that provides contextual information to the spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internationalization, checksum scheduling.
  • Spring AOP: With the configuration management feature, the Spring AOP module directly integrates aspect-oriented programming capabilities into the spring framework. Therefore, it is easy to enable any object managed by the Spring framework to support AOP. The Spring AOP module provides transaction management services for objects in spring-based applications. By using Spring AOP, you can integrate declarative transaction management into your application without relying on EJB components.
  • Spring DAO: The JDBC DAO abstraction layer provides a meaningful exception hierarchy that can be used to manage exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the number of exception codes that need to be written (such as opening and closing connections). Spring DAO's JDBC-oriented exception conforms to the common DAO exception hierarchy.
  • Spring ORM: The Spring Framework inserts several ORM frameworks, providing ORM object-relational tools, including JDO, Hibernate, and IBatis SQL Map. All of these conform to Spring's common transaction and DAO exception hierarchies.
  • Spring Web Module : The Web context module is built on top of the application context module and provides the context for Web-based applications. Therefore, the Spring framework supports integration with Jakarta Struts. The Web module also simplifies the process of working with multipart requests and binding request parameters to domain objects.
  • Spring MVC Framework : The MVC framework is a full-featured MVC implementation of building WEB applications. With the policy interface, the MVC framework becomes highly configurable, and MVC accommodates a large number of view technologies, including JSP, Velocity, Tiles, IText, and POI.

The functionality of the Spring framework can be used in any Java EE server, and most features are also available in an out-of-management environment. The core point of Spring is to support reusable business and data access objects that are not tied to a particular Java EE service. There is no doubt that such objects can be reused across different Java EE environments (Web or EJB), standalone applications, and test environments.

IOC and AOP

aspect-oriented programming , AOP, is a programming technique that allows programmers to modularize the behavior of crosscutting concerns or crosscutting typical lines of responsibility, such as logging and transaction management. The core structure of AOP is the facet , which encapsulates behaviors that affect multiple classes into reusable modules.

AOP and IOC are complementary technologies that use a modular approach to solve complex problems in enterprise application development. In a typical object-oriented development approach, logging statements may be placed in all methods and Java classes in order to implement logging functionality. In the AOP approach, the log service can be modularized in turn and applied declaratively to the component that needs the log. Of course, the advantage is that the Java class does not need to know the existence of the log service and does not need to consider the associated code. Therefore, application code written in Spring AOP is loosely coupled.

The functionality of AOP is fully integrated into the context of Spring transaction management, logging, and various other features.

The core of Spring design is the org.springframework.beans package, which is designed to be used with the JavaBean component. This package is not usually used directly by the user, but is used by the server as the underlying intermediary for most other functions . The next highest-level abstraction is the BeanFactory interface , which is the implementation of the factory design pattern, allowing objects to be created and retrieved by name. BeanFactoryYou can also manage the relationships between objects.

BeanFactorySupports two object models.

    • A single-state model provides a shared instance of an object with a specific name that can be retrieved at query time. Singleton is the default and most commonly used object model. Ideal for stateless service objects.
    • The prototype model ensures that each retrieval creates a separate object. The prototype model works best when each user needs his or her own object.

The Bean Factory concept is the basis of Spring as an IOC container. The IOC shifts responsibility for handling things from application code to frameworks . The Spring framework uses the JavaBean property and configuration data to indicate the dependencies that must be set.

Beanfactory interface

Because org.springframework.beans.factory.BeanFactory it is a simple interface, it can be implemented for a variety of underlying storage methods. The most common BeanFactory definition is XmlBeanFactory that it loads beans based on the definitions in the XML file.

New Xmlbeanfactory (new fileinputsteam ("Mybean.xml"));

The beans defined in the XML file are negatively loaded, which means that the bean itself will not be initialized until the bean is needed. To BeanFactory retrieve a bean, simply call the getBean() method and pass in the name of the bean that will be retrieved.

Mybean Mybean = (Mybean) factory.getbean ("Mybean");

Each bean's definition can be POJO (with the class name and JavaBean initialization property definition) or FactoryBean . FactoryBeaninterface adds an indirect level to an application built using the Spring framework.

Spring Framework Learning (1) Spring Introduction

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.