"Internet Architecture" Software Architecture-Overview of Spring Structure of Spring Source Code (8)

It has been almost 10 years since spring was exposed in 2007 to the current 2018. Why has a Java framework been popular for so many years? Many people are familiar with the use of spring, but they have never interpreted the source code of spring. Lao Tie will take a look at the source code with me and understand the internal structure. Only those who have read the source code can obtain superior martial arts. Software development is not just about moving bricks. Old iron. Familiar with the principles of internal power, and flexible use of external power. Internal power is like electricity, and external power is like motor. The stronger the power of internal power, the greater the horsepower of the motor can play a huge role. On the contrary, if the power is weak, the horsepower will not work. Spring has grown from a single jar package to more than ten jar packages, from spring mvc to spring boot to spring cloud. From the need to configure to the current 0 configuration, the packaging is getting more and more powerful. As a result, if you don’t understand the kernel is strong If you encounter problems, you may not be able to start. It is especially important to read the spring source code together.

spring

####history

Official website: https://github.com/spring-projects/spring-framework

I have been with me since I started programming in java. I first came into contact with spring in 2007. I have been using spring since my java programming career, and I haven't been to that company and I haven't used spring. I remember that ssh (struts+spring+hibernate) was popular at that time, and everyone would write proficient ssh on their resumes. These three frameworks are known as troikas. With the development of spring becoming larger and larger, it gradually upgraded from the middle service to spring mvc upwards, spring jdbc and springvm downwards. As the use of struts and hibernate slowly declined, struts was slowly Spring mvc is replaced, hiberntate has been basically replaced by mybatis. As of the time I write this article spring v5.1.3

In 2002, developers Juergen Hoeller and Yann Caroff persuaded Rod Johnson to create an open source project based on infrastructure code. Rod, Juergen and Yann started working together on this project around February 2003. Yan created the name "Spring" for the new framework. According to Rod, Spring is a new beginning after the "winter" of traditional J2EE!

Rod Johnson's book introduces the world of J2EE best practices in a very detailed, detailed and practical way. From coding standards, idioms, unit testing, design decisions, persistence, caching, EJB, model-2 presentation layer, views, verification techniques to fair criticism of performance, readers can experience from theory to practice, constraints, risks and the most Good practice. This book is indeed a knowledge base.

In June 2003, Spring 0.9 was released under the Apache 2.0 license. In March 2004, version 1.0 was released. Interestingly, even before the 1.0 release, Spring was widely adopted by developers. In August 2004, Rod Johnson, Juergen Hoeller, Keith Donald and Colin Sampaleanu co-founded interface21, a company specializing in Spring consulting, training and support.

Yann Caroff left the team early. Rod Johnson left the team in 2012. Juergen Hoeller is still an active member of the Spring development team.

Since version 1.0 was released in 2004, the Spring framework has developed rapidly. Spring 2.0 was released in October 2006, and by that time, Spring had over 1 million downloads. Spring 2.0 has an extensible XML configuration function to simplify XML configuration, supports Java 5, additional IoC container extensions, and supports dynamic languages ​​(such as groovy, aop enhancements and new bean ranges).

Interface21, which managed the Spring project under Rod’s leadership, changed its name to SpringSource in November 2007. At the same time, Spring 2.5 was released. The main new features in Spring 2.5 include support for Java 6/Java EE 5, support for annotation configuration, automatic detection of components in the classpath, and OSGi-compatible bundles.

In 2007, SpringSource received Series A financing ($10 million) from capital. SpringSource raised additional capital in 2008 through funding from accelerated partners and Series B. SpringSource acquired a number of companies (Covalent, Hyperic, G2One, etc.) during this period. In August 2009, SpringSource was acquired by VMWare for $420 million! SpringSource acquired cloud foundry within a few weeks, which is a cloud PaaS provider. In 2015, cloud foundry was transferred to the non-profit cloud foundry foundation.

In December 2009, Spring 3.0 was released. Spring 3.0 has many important features, such as reorganization of the module system, support for Spring expression language, Java-based bean configuration (JavaConfig), support for embedded databases (such as HSQL, H2 and Derby), model verification/REST support and support for Java EE 6 support.

Many minor versions of the 3.x series were released in 2011 and 2012. In July 2012, Rod Johnson left the team. In April 2013, VMware and EMC created a joint venture called Pivotal through GE investment. All 6 application projects have been transferred to Pivotal.

In December 2013, Pivotal announced the release of Spring Framework 4.0. Spring 4.0 is a major advancement of the Spring framework. It includes full support for Java 8, higher third-party library dependencies (groovy 1.8+, ehcache 2.1+, hibernate 3.6+, etc.), Java EE 7 support, and groovy DSL For bean definition, support for websockets and support for generic types are used as qualifiers for injected beans.

Many Spring framework 4.xx versions were released from 2014 to 2017. The current Spring framework version (4.3.7) was released in March 2017. Spring framework 4.3.8 was released in April 2017 and will be the last in the 4.x series. The next major version of the Spring Framework will be launched in version 5.0.

####Architecture

The functions of each module are as follows:

Core Container

The core container includes spring-core , spring-beans , spring-context , spring-context-support and spring-expression (SpEL, Spring Expression Language, Spring Expression Language) modules.

The spring-core and spring-beans modules are [the foundation of the Spring Framework], including functions such as inversion of control and dependency injection. BeanFactory is a subtle implementation of the factory pattern. It removes the need for coding singletons and can decouple configuration and dependencies from the actual coding logic.

The [Context] ( spring-context ) module is built on the basis of the [Core and Bean] module, which accesses objects in a way similar to JNDI registration. The Context module inherits from the Bean module and adds functions such as internationalization (for example, using resource bundles), event propagation, resource loading, and transparent creation of context (for example, through the Servelet container). The Context module also supports Java EE functions, such as EJB, JMX, and remote calls. The ApplicationContext interface is the focus of the Context module. spring-context-support provides support for integrating third-party libraries into the Spring context, such as caching (EhCache, Guava, JCache), mail (JavaMail), scheduling (CommonJ, Quartz), template engines (FreeMarker, JasperReports, Velocity), etc. .

The spring-expression module provides a powerful [expression language] for querying and manipulating object graphs at runtime. It is an extension of the unified expression language defined in the JSP2.1 specification. It supports set and get attribute values, attribute assignments, method calls, access to the contents of array collections and indexes, logical arithmetic operations, named variables, and access to Spring IoC containers by name Retrieve objects, and support projection, selection, and aggregation of lists.

AOP and Inspection (Instrumentation)

The spring-aop module provides the implementation of [Aspect Oriented Programming] (AOP), which can define methods such as interceptors and pointcuts, so as to completely decouple the code that implements the functions. Using source-level metadata, behavioral information can be incorporated into the code in a manner similar to .Net attributes.

The spring-aspects module provides integration to AspectJ.

The spring-instrument module provides support for detection classes and the implementation of class loaders for specific application servers. javaagent support and class loader. The spring-instrument-tomcat module contains Spring instrumentation agents for tomcat.

Message processing (messaging)

The spring-messaging module included in Spring 4 is extracted from the key abstractions of Spring integration projects, including Message , MessageChannel , MessageHandler and other projects that serve message processing. This module also contains a series of annotations for mapping messages to methods, similar to the annotations based on the coding model of Spring MVC.

Data access and integration

The data access and integration layer includes JDBC, ORM, OXM, JMS and transaction modules. 
(Translator's Note: JDBC=Java Data Base Connectivity, ORM=Object Relational Mapping, OXM=Object XML Mapping, JMS=Java Message Service)

The spring-jdbc module provides the [JDBC] abstraction layer, which eliminates lengthy JDBC coding and analysis of database vendor-specific error codes.

The spring-tx module supports [programmatic transaction and declarative transaction], which can be used for classes that implement specific interfaces and all POJO objects. 
(Translator's Note: Programmatic transactions need to write their own transaction management methods such as beginTransaction(), commit(), rollback(), declarative transactions are automatically processed by spring through annotations or configuration, and programmatic transactions are more granular)

The spring-orm module provides integration of popular [Object Relational Mapping] APIs, including [JPA], [JDO] and [Hibernate]. Through this module, these ORM frameworks can be integrated with other spring functions, such as the transaction management mentioned above.

The spring-oxm module provides support for [OXM] implementation, such as JAXB, Castor, XML Beans, JiBX, XStream, etc.

The spring-jms module contains the functions of producing and consuming messages. Starting from Spring 4.1, the spring-messaging module has been integrated .

Web

The web layer includes spring-web , spring-webmvc , spring-websocket , spring-webmvc-portlet and other modules.

The spring-web module provides basic web - oriented functions and web-oriented application contexts, such as multipart file uploading, using Servlet listeners to initialize IoC containers, etc. It also includes the HTTP client and web-related parts of Spring remote calls.

The spring-webmvc module (ie, the Web-Servlet module) provides the realization of model view control ([MVC]) and REST Web services for web applications. Spring's MVC framework can completely separate the domain model code and web forms, and can be integrated with all other functions of the Spring framework.

The spring-webmvc-portlet module (ie Web-Portlet module) provides an MVC implementation for the Portlet environment and reflects the functions of the spring-webmvc module.

Test

The spring-test module supports [unit testing] and [integration testing] through JUnit and TestNG components. It provides a consistent [load] and [cache] Spring context, and also provides a [mock object] (mock object) for testing code individually.

  • Download spring fremwork source code

Configure acceleration function Windows environment

C:\Windows\System32\drivers\etc\hosts

Add two sentences at the end:

151.101.185.194 http://github.global.ssl.fastly.net
192.30.253.112 http://github.com

Configure acceleration function, linux environment

vi /etc/hosts
/etc/init.d/networking restart

Add
151.11.185.194 http://github.global.ssl.fastly.net
192.30.253.112 http://github.com

git clone https://github.com/spring-projects/spring-framework.git
#切换到对应分支
git checkout -b v4.3.8 v4.3.8.RELEASE

Idea can be imported directly, if there is no gradle idea, it will be downloaded automatically

Interview scene review

  • Review the previous interview experience and
    talk about spring IOC

When there is no spring ioc, if we need to use a class,

1. Through the new method
2. Through another class new and then passed to the specified class.
No matter what kind of method, it will make our previous dependencies very messy. The code is full of new and the initialization of the service Also very confusing.
With the IOC container, you can manage the service class or bean, and then inject it into the specified class by declaring it. XML technology is used in it to define and parse our bean. This is the reflection technology. In order to inject a bean into another bean, the abstract factory pattern is also used. To tell the truth is to save time for programmers and say whether this sentence is impeccable.

PS: Go straight to the source code learning. Springboot and springcloud are slowly becoming mainstream. Many large-scale frameworks are based on spring. I believe that after reading the commonly used spring source code, the road will become wider and wider in the future. I will add more of my own experience in the following blog posts, and learn the spring source code in more detail.

Guess you like

Origin blog.csdn.net/zhugeaming2018/article/details/108577197