Home >Java >javaTutorial >Spring core framework architecture

Spring core framework architecture

巴扎黑
巴扎黑Original
2017-04-30 10:13:581626browse

Many people are using spring to develop java projects, but when configuring maven dependencies, it is not clear which spring jars to configure. They often add a bunch of them randomly, and then continue to configure the jar dependencies when compilation or running errors are reported, resulting in confusion of spring dependencies, or even downloading. When creating the same type of project at a time, I don’t know which spring dependencies to configure, I can only copy them. In fact, that’s what I did at the beginning!

There are only about 20 jar packages in spring, each with corresponding functions. One jar may also depend on several other jars. Therefore, it is concise and clear to understand the relationship between them and configure maven dependencies. Here is an example: To use the spring framework in ordinary java projects, what jars are needed? Just one

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.2.17.RELEASE</version>
</dependency>

What about introducing spring mvc into web projects? Just configure a dependency

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.2.17.RELEASE</version>
</dependency>

Why can it be configured like this? Next, we take the spring 3.2.17.RELEASE version as an example to introduce the spring framework structure. Spring 4 is slightly different and will be introduced at the end

The spring official website gives a structure diagram of spring3

The picture divides spring into 5 parts: core, aop, data access, web, and test. Each rounded rectangle in the picture corresponds to a jar. If configured in maven, the "groupId" of all these jars is "org" .springframework", each jar has a different "artifactId", in addition, "instrumentation" has two jars, and a "spring-context-support" is not listed in the figure, so there are 19 jar packages for spring3 in total.

The following introduces the jars and dependencies of these five parts

core

The core part contains 4 modules

  1. spring-core: The most basic implementation of dependency injection IoC and DI


  2. spring-beans: Bean factory and bean assembly


  3. spring-context: spring's context context is the IoC container


  4. spring-expression: spring expression language

Their complete dependencies

Because spring-core relies on commons-logging, and other modules rely on spring-core, the entire spring framework relies on commons-logging. If you have your own log implementation such as log4j, you can eliminate the dependence on commons-logging. No Log implementation excludes commons-logging dependency, compilation error

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.2.17.RELEASE</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

aop

The aop part contains 4 modules

  1. spring-aop: aspect-oriented programming


  2. spring-aspects: Integrate AspectJ


  3. spring-instrument: Provides some class-level tool support and ClassLoader-level implementation for server


  4. spring-instrument-tomcat: instrument implementation for tomcat

Their dependencies

data access

The data access part contains 5 modules

  1. spring-jdbc: jdbc support


  2. spring-tx: transaction control


  3. spring-orm: object relational mapping, integrated orm framework


  4. spring-oxm: object xml mapping


  5. spring-jms:java message service

Their dependencies

web

The web part contains 4 modules

  1. spring-web: basic web functions, such as file upload


  2. spring-webmvc: mvc implementation


  3. spring-webmvc-portlet: portlet-based mvc implementation


  4. spring-struts: Integration with struts, not recommended, spring4 no longer provides

Their dependencies

test

There is only one module in the test part. I will also put spring-context-support here

  1. spring-test: spring test, providing junit and mock testing functions


  2. spring-context-support: spring additional support packages, such as mail service, view analysis, etc.

Their dependencies

This is the end of the introduction to spring 3. Looking at these pictures, I believe you will no longer be confused when configuring spring dependencies in maven.

The following introduces spring4, which is basically the same structure as spring3. The following is the structure diagram given by the official website

As you can see, the struts of spring3 have been removed from the picture, messaging and websocket have been added, and other modules remain unchanged. Therefore, there are 20 jars of spring4

  1. spring-websocket: An efficient communication tool for web applications


  2. spring-messaging: for building messaging-based applications

Their dependencies

The above is the detailed content of Spring core framework architecture. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn