Lightweight Java Development Framework Spring

Source: Internet
Author: User
Tags to domain

Spring is an open source framework, and spring is a lightweight Java development framework that emerged in 2003 by Rod Johnson in his book expert one-on-one development and Some of the concepts and prototypes elaborated in design are derived. It is created to address the complexities of enterprise application development. One of the main advantages of the framework is its layered architecture, which allows the user to choose which component to use, while providing an integrated framework for Java EE application development. Spring uses basic JavaBean to accomplish things that were previously only possible by EJBS. However, the use of spring is not limited to server-side development. From the standpoint of simplicity, testability, and loose coupling, any Java application can benefit from spring. The core of spring is control inversion (IoC) and facet-oriented (AOP). In short, spring is a layered javase/eefull-stack ( one-stop) lightweight open-source framework.

Objective: To solve the complexity of enterprise application development

Function: Use basic JavaBean instead of EJB, and provide more enterprise application function

Scope: Any Java application

In short, spring is a lightweight, dependency injection (IoC) and facet-oriented (AOP) container framework.

Lightweight -Spring is lightweight both in terms of size and overhead. The full spring framework can be published in a jar file with a size of more than 1MB. and the processing overhead required by spring is negligible. In addition, spring is non-intrusive: Typically, objects in spring applications do not depend on a particular class of spring.

control reversal --spring facilitates loose coupling through a technique called inversion of Control (IoC). When an IOC is applied, other objects that an object relies on are passed in passively, rather than the object itself creating or locating dependent objects. You can think of the IOC as opposed to Jndi--not the object looking for dependencies from the container, but the container actively passing the dependency to it when the object is initialized without waiting for the object to be requested.

facet-oriented --spring provides rich support for aspect-oriented programming, allowing for the development of cohesion through the separation of application business logic with system-level services such as auditing (auditing) and transaction (transaction) management. The Application object only implements what they should do-complete the business logic-that's all. They are not responsible (or even conscious) for other system-level concerns, such as log or transaction support.

The container --spring contains and manages the configuration and lifecycle of the Application object, in this sense it is a container, and you can configure how each of your beans is created-based on a configurable prototype (prototype), Your bean can create a separate instance or generate a new instance each time it is needed-and how they relate to each other. However, spring should not be confused with traditional heavyweight ejb containers, which are often bulky and cumbersome and difficult to use.

Framework --spring can be used to configure and assemble simple components into complex applications. In spring, application objects are combined declaratively, typically in an XML file. Spring also provides a number of basic functions (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.

All of these features of spring enable you to write cleaner, more manageable, and easier-to-test code. They also provide basic support for the various modules in spring.

Aop

The basic concept of control reversal mode (also known as dependency injection) is that you do not create objects, but describe how they are created. The code does not directly connect to objects and services, but describes in the configuration file which component requires which service. Containers (which are IOC containers in the Spring framework) are responsible for linking these together. In a typical IOC scenario, the container creates all the objects and sets the necessary properties to connect them together, deciding when to invoke the method. The following table lists an implementation pattern for the IOC.

Type 1 Services need to implement specialized interfaces through interfaces that provide these services from objects, and can query dependencies from objects (for example, required additional services) "interface injection".
Type 2 The dependency "Setter method Injection" is assigned by JavaBean properties, such as setter methods.
Type 3 Dependencies are provided as constructors and do not expose "constructor injection" in the form of a JavaBean property.

The IOC container for the Spring framework is implemented with type 2 and type 3.

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.

In AOP programming, Spring offers many features, such as PointCut, Advice, and Advisor, which are roughly the point of entry for transaction management, logging, and various other features.

IOC

The core of the 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. Beanfactory can also manage the relationships between objects.

The beanfactory supports two object models.

1. A single-state model provides a shared instance of an object with a specific name, which can be retrieved at query time. Singleton is the default and most commonly used object model. Ideal for stateless service objects.

2. 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.

You might be thinking, "Spring is just another framework." Why do we need the spring framework when there are already many open source (and proprietary) Java EE frameworks?

Spring is unique for a number of reasons:

    1. It locates areas that are not in many other popular frameworks. Spring is dedicated to providing a way to manage your business objects.
    2. Spring is comprehensive and modular. Spring has a layered architecture, which means that you can choose to use any part of it that is isolated, and that its architecture remains inherently stable. So from your study, you can get the greatest value. For example, you might choose to use spring only to simplify the use of JDBC, or to manage all business objects.
    3. It's designed from the bottom to help you write code that is easy to test. Spring is the ideal framework for testing drive engineering.
    4. Spring does not require more than one framework for your project. Spring is a potentially one-stop solution for most of the infrastructure associated with typical applications. It also relates to content that is not considered by other frameworks.

SPIRNG Features:

The powerful JavaBeans-based configuration management with the inversion of CONTROL,IOC principle makes application components faster and easier.

A core Bean factory that can be used in different operating environments, from applets to Java EE.

The generalized abstraction layer of a database transaction, allowing the declarative (declarative) transaction manager to simplify the partitioning of the transaction so that it is not related to the underlying.

The built-in generalized policy for JTA and a single JDBC data source makes Spring's transactional support do not require a Java EE environment, as opposed to a generic JTA or EJB CMT.

The JDBC abstraction layer provides a targeted exception level (no longer extracting the original code from the SQL exception), simplifying error handling and greatly reducing the amount of coding the programmer has. When using JDBC again, you don't have to write another ' terminate ' (finally) module. and JDBC-oriented exceptions match the spring Universal Data Access object exception level.

Integrates with Hibernate,jdo and IBATIS SQL Maps in the form of resource containers, DAO implementations, and transaction policies. Many typical hibernate integration problems are solved by using many of the inversion control convenience features to fully support. All of these comply with the spring general transaction and generic data Access object exception level specification.

Flexible MVC Web application framework based on core Spring features. The developer will have a high degree of control over the framework through the policy interface, so the framework will adapt to a variety of rendering (View) technologies such as Jsp,freemarker,velocity,tiles,itext and POI. It is worth noting that the Spring middle tier can easily be combined with any MVC framework-based web layer, such as struts,webwork, or Tapestry.

Provides an aspect-oriented programming (AOP) framework for services such as transaction management.

Spring Features:

Easy to decouple, simplify development

With the IOC container provided by spring, we can control the dependencies between objects by spring, avoiding excessive program coupling caused by hard coding. With spring, users no longer have to write code for these very low-level requirements, such as single-instance pattern classes, attribute file parsing, and can focus more on upper-tier applications.

AOP Programming Support

Provides easy-to-face programming with the AOP features provided by spring, and many features that are not easy to implement with traditional oop can be easily coped with through AOP.

declarative Transaction support

In spring, we can free ourselves from the tedious transaction management code, and make the management of the transaction in a declarative way to improve the efficiency and quality of development.

Easy-to-program testing

Can do almost all of the testing in a non-container-dependent way, and in spring, testing is no longer an expensive operation, but something that can be done at hand.

Easy integration of a variety of excellent frameworks

Spring does not exclude a variety of excellent open source frameworks, instead, spring can reduce the difficulty of using various frameworks, Spring provides a variety of excellent frameworks such as struts, Hibernate, Hessian, Quartz, etc.), direct support.

reduce the difficulty of using the Java EE API

Spring provides a thin layer of encapsulation for many difficult Java EE APIs, such as Jdbc,javamail, remote invocation, and so on. These Java EE APIs are significantly less difficult to use with spring's simple encapsulation.

Java source code is a classic learning paradigm

Spring's source design is subtle, well-structured, and unique, and embodies the master's flexibility in Java design patterns and the mastery of Java technology. The spring framework source code is undoubtedly a best practice example of Java technology. If you want to quickly improve your Java technology and application development level in a short period of time, learning and studying spring source code will make you receive unexpected results.

The benefits spring brings to our projects:

Spring effectively organizes your middle-tier objects, whether or not you choose to use EJBS. If you just use struts or other frameworks that contain the Java EE-specific APIs, you'll find that spring is focused on the legacy.

Spring can eliminate the excessive use of singleton in many projects. Based on my experience, this is a major problem, which reduces the testability and object-oriented nature of the system.

Spring eliminates the need to customize files with attributes in a variety of formats, and is configured in a consistent way throughout the application and engineering. Ever confused, a particular class looking for a psychedelic attribute keyword or system attribute, do you have to read Javadoc or even source code? With spring, you can easily see the JavaBean property of the class. The use of inverted controls (discussed below) helps to accomplish this simplification.

Spring can promote good programming habits through interfaces rather than classes, reducing programming costs to almost zero.

Spring is designed so that applications created with it depend as little as possible on his APIs. Most business objects in a spring application are not dependent on spring.

Applications built using spring are easy to unit test.

Spring enables the use of EJBS to be an implementation choice, not an inevitable choice for application architectures. You can choose to use POJOs or local EJBS to implement the business interface without affecting the calling code.

Spring helps you solve many problems without using EJBS. Spring provides an alternative to EJBS that are suitable for many Web applications. For example, spring can use AOP to provide declarative transactions without using an EJB container, if you only need to deal with a single database, and you don't even need a JTA implementation.

Spring provides a consistent framework for data access, whether using JDBC or O/R mapping products such as hibernate.

Spring does enable you to solve your problem with the simplest possible solution. These features are of great value.

To sum up, spring has the following advantages:

  1. Low-intrusive design with very low code contamination
  2. True commitment to write Once,run anywhere, independent of various application servers
  3. Spring's di mechanism reduces the complexity of business object substitution
  4. Spring is not entirely dependent on spring, and developers are free to select part or all of the spring framework

Spring Effect:

Spring provides a number of features, where I'll quickly show each of its main aspects in turn.

First, let's clarify the spring range. Although spring covers many aspects, we already have a clear concept of what it should involve and what should not be involved. The main purpose of

Spring is to make the Java EE easy to use and promote good programming habits.

Spring does not re-develop what is already there. Therefore, in spring you will find a packet without logging, no connection pool, and no distributed transaction scheduling. These are available in open source projects (for example Commons Logging is used to do all the log output, or commons dbcp used as a data connection pool) or provided by your application server. For the same reason, we did not provide the O/R mapping layer, and there are friendly solutions such as Hibernate and JDO. Spring's goal is to make existing technologies easier to use .

For example, although we do not reconcile the underlying transaction, we provide an abstraction layer that overrides JTA or any other transaction policy.

Spring does not compete directly with other open source projects unless we feel that we can offer something new. For example, like many developers, we have never been happy with struts and feel that there is room for improvement in the MVC Web framework. In some areas, such as the lightweight IOC container and the AOP framework, Spring has direct competition, but there are no already popular solutions in these areas. (Spring is a pioneer in these areas.)

Spring also benefits from intrinsic consistency.

All the developers are singing the same hymn, the basic idea is still the expert one-on-one EE design and development of those.

And we have been able to use some of the main concepts, such as inverted control, to handle multiple areas.

Spring is portable between application servers.

Certainly ensures portability is always a challenge, but we avoid any particular platform or non-standardization, and support users on Weblogic,tomcat,resin,jboss,websphere and other application servers.

Spring Basic 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: 1. Core container: The core container provides the basic functionality of the spring Framework (Spring Core). The main component of the core container is Beanfactory, which is the implementation of the factory pattern. The beanfactory uses the inversion of control (IOC) pattern to separate the application's configuration and dependency specifications from the actual application code.

2. 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.

3. Spring AOP: With the configuration management feature, the Spring AOP module directly integrates the aspect-oriented programming functionality 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.

4. The Spring dao: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.

5. The Spring orm:spring Framework inserts several ORM frameworks, providing ORM object-relational tools, including JDO, Hibernate, and Ibatissql Map. All of these conform to Spring's common transaction and DAO exception hierarchies.

6. 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.

7. 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 model is composed of JavaBean, which is stored in map, the view is an interface, is responsible for displaying the model, and the controller represents the logic code. 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.

Lightweight Java Development Framework Spring

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.