Chapter 1 Spring source code reading preface and outline

foreword

Spring is an excellent enterprise framework. It is lightweight, simple, complete, open, inclusive, integrated, advancing with the times, and innovative. After a profound lesson, in Lao Hu's business project, it is impossible to leave the excellent business framework of spring.

Lightweight

When spring debuted in 2003, the enterprise-level solution at that time was only ejb2.0 of sun company, and ejb was an enterprise-level one-stop solution for a huge abscess. Maybe only a small function is needed, but all jars need to be added. At that time, spring only had beans, aop, tx and context. And no jdbc and mvc. The basic dependencies are more than ten M. Spring integrates struts1, hibernate, and directly replaces ejb, bringing a bright dawn

Simple

The functionality is complex, but provides a simple solution. such as dependencies, etc.

perfect, open

Spring has perfect support for enterprise-level basic development. For example, it supports strtus2, hibernate, jms, etc. It is easy to expand the functions you want in the design and architecture of spring, and there are ways to expand the basic details of each core.

Inclusive, integrated, advancing with the times

Spring has a good ecosystem and provides sound support for commonly used technologies. Can be easily integrated into the project

innovation

spring-boot integrated development and runtime framework. It has basically changed the current development method and operation method.

Compared

ejb4.0

ejb4.0 is much lighter than ejb2.0, but the community strength is very weak.

jfinal

jfinal has very weak support for other technologies. More suitable for smaller projects that do not require expansion

shortcoming

Spring has a lot of advantages, solves a lot of problems, and uses a lot of design patterns. After reading the source code, I feel that spring still has a lot of problems.

  1. It feels a bit abusing the design pattern, and the little details are well designed to be very large.
  2. Various compatibility, the pursuit of a large and comprehensive way. Makes the code unreadable and very complicated.
  3. Many codes have a long history and are constantly expanding, and some core points have not been optimized, integrated, rewritten, and refactored.
  4. Some modules are designed to be very complex.
  5. Some code is not open source, uncomfortable
  6. It is very troublesome to build a development environment

lesson

I wrote a project a long time ago with no framework in it. Persistence is directly using jdbc, a programmatic thing. a lot of code

public void addUser(User user){
		DruidPooledConnection conn = null;
		PreparedStatement ps = null;
		try {
			conn = druidDataSource.getConnection( );
			conn.setAutoCommit( false );
			ps = conn.prepareStatement( "** ")
			conn.commit( );
		}catch ( Exception e ) {
			try {
				conn.rollback( );
				log.error( e.getMessage( )  , e  );
			} catch ( SQLException e1 ) {
				log.error( e1.getMessage( ) , e );
			}
		}finally{
			try {
				conn.recycle( );
				if(ps != null){
					ps.close( );
				}
			} catch ( SQLException e ) {
				log.error( e.getMessage( )  , e  );
			}
		}
}

While causing a lot of development workload, the scalability of programmatic things is not well divided, and it is easy to forget to commit or roll back, resulting in nested things. The workload of development and maintenance is increased, and it is easy to remove problems online.

public void addUser(User user){
	userMapper.addUser(user);
}

Wait, wait, etc., and then spring was introduced, and everything became very simple. Just focus on business development.

The modules to be interpreted are

  1. spring-core
  2. spring-bean
  3. spring-aop
  4. spring-tx (I'm not very interested in the spread of things in spring-tx, so I won't interpret it here)
  5. spring-context
  6. spring-jdbc (datasource submodule)
  7. spring-boot

This is the basic dependency graphspring module dependency graph

After reading the dependency graph, paste the simplest maven dependency configuration

<properties>
		<spring-version>.....</spring-version>
		<spring-boot-version>.....</spring-boot-version>
</properties>
<dependencies>
	<!-- 最低依赖,可以用分布式生产者 -->
	<dependency>
	  <groupId>org.springframework</groupId>
	  <artifactId>spring-context-support</artifactId>
	  <version>${spring-version}</version>
	</dependency>
	<!-- spring 集成 其他mvc框架,最低依赖 -->
	<dependency>
	  <groupId>org.springframework</groupId>
	  <artifactId>spring-web</artifactId>
	  <version>${spring-version}</version>
	</dependency>
	<!-- spring mvc 最低依赖。-->
	<dependency>
	  <groupId>org.springframework</groupId>
	  <artifactId>spring-webmvc</artifactId>
	  <version>${spring-version}</version>
	</dependency>

	<!-- spring boot 最低依赖 -->
	<dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-actuator</artifactId>
	  <version>${spring-boot-version}</version>
	</dependency>
	<dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-starter</artifactId>
	  <version>${spring-boot-version}</version>
	</dependency>
	
	<!-- spring bott 最简单,脑残的依赖方式 想用什么 就继承什么 -->
	<parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starters</artifactId>
           <version>${spring-boot-version}</version>
        </parent>
</dependencies>
Interpret source selection

This series of source code interpretation only describes the core modules of spring. Grasp the core, grasp the key points, analyze layer by layer, and analyze it. After the analysis, I found that there is really not much in spring. Some compatible, supported and extended modules will not be interpreted. No interpretation will be made of outdated technical points. For example, xml-related technologies do not interpret some rarely used technologies and support. If you have a deep understanding of the core modules, other modules are relatively easy.

content

Chapter 1 Spring source code reading preface and outline

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939387&siteId=291194637
Recommended