Home >Java >javaTutorial >Spring core framework architecture
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
The core part contains 4 modules
spring-core: The most basic implementation of dependency injection IoC and DI
spring-beans: Bean factory and bean assembly
spring-context: spring's context context is the IoC container
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>
The aop part contains 4 modules
spring-aop: aspect-oriented programming
spring-aspects: Integrate AspectJ
spring-instrument: Provides some class-level tool support and ClassLoader-level implementation for server
spring-instrument-tomcat: instrument implementation for tomcat
Their dependencies
The data access part contains 5 modules
spring-jdbc: jdbc support
spring-tx: transaction control
spring-orm: object relational mapping, integrated orm framework
spring-oxm: object xml mapping
spring-jms:java message service
Their dependencies
The web part contains 4 modules
spring-web: basic web functions, such as file upload
spring-webmvc: mvc implementation
spring-webmvc-portlet: portlet-based mvc implementation
spring-struts: Integration with struts, not recommended, spring4 no longer provides
Their dependencies
There is only one module in the test part. I will also put spring-context-support here
spring-test: spring test, providing junit and mock testing functions
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
spring-websocket: An efficient communication tool for web applications
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!