Supplement 1: Understanding of Spring Framework and IOC AOP

table of Contents:

Spring Framework

Spring IoC

Spring AOP

 

 

Spring Framework

Spring Core: Basic, it can be said that all other functions of Spring need to rely on this library.

           Mainly provide Ioc dependency injection function

Spring Aspects: This module provides support for integration with AspectJ

Spring AOP: Provides an aspect-oriented programming implementation

Spring JDBC: Java database connection

Spring JMS: Java Message Service

Spring ORM: used to support ORM tools such as Hibernate

Spring Web: Provide support for creating web applications

Spring Test: Provides support for JUnit and TestNG testing

 

 

 

 

 

 

 

What is AspectJ

AspectJ is an aspect-oriented framework. It defines some grammars of AOP and has a special bytecode generator to generate class files that comply with the Java specification.

 

Object Relational Mapping (ORM) mode is a technology to solve the mismatch between object-oriented and relational databases.

ORM provides another mode for implementing the persistence layer. It uses mapping metadata to describe the mapping of object relationships, so that ORM middleware can act as a bridge between the business logic layer and the database layer of any application.

https://blog.csdn.net/Andy_ayu/article/details/78464020

 

What is O/X Mapper?  

 

A new feature of Spring 3.0 is O/X Mapper. The concept of O/X mapper is not new. O stands for Object and X stands for XML. Its purpose is to convert back and forth between a Java object (almost always a plain old Java object, or POJO for short) and an XML document.

 

For example, you may have a simple bean with several properties, and your business needs to convert that Java object into an XML document. Spring's O/X Mapper can solve that problem for you. If the other way round, you need to convert an XML document into a simple Java bean, Spring's O/X Mapper can also do it.

https://www.cnblogs.com/xuxiuxiu/p/6653060.html

 

What is Spring Portlet?

 

For JSR-168 Portlet, Spring also provides a similar MVC framework. The main difference between portlet workflow and servlet is that portlet request processing has two unique stages: Action stage and Render stage. During the action phase, there will be "background" data change or action code, which will only be executed once. The display phase will produce the display content that the user sees every time it refreshes. During the entire processing of a single request, the action phase will only be executed once, while the display phase may be executed multiple times. This requires a clear layering between the activities that change the persistent state of the system and the activities that produce the displayed content. The Spring Portlet MVC framework reflects this well.

https://www.ibm.com/developerworks/cn/java/j-lo-spring2-portal/

https://www.coder.work/article/6598242

 

Portal, as a web application, is usually used to provide personalized, single-login, and aggregate content from various information sources, and serves as the host of the presentation layer of the information system.

https://blog.51cto.com/fengbohaishang/989144

 

 

 

Spring IoC

IoC (Inversion of Control) is a design idea, that is, the control of objects created manually in the program is handed over to the Spring framework to manage. IoC is also used in other languages ​​and is not unique to Spring. The IoC container is the carrier that Spring uses to implement IoC. The IoC container is actually a Map (key, value), and various objects are stored in the Map.

The IoC container is like a factory. When we need to create an object, we only need to configure the configuration file/annotation, without considering how the object is created.

The initialization process of Spring IoC:

For example:

(1) There is a WelcomeService service interface in the service layer. Generally, it is through WelcomeService service = new WelcomeServiceImpl(); to create an instance and call:

 

(2) Due to the difference between the actual application environment and the test environment, the WelcomeServiceImpl needs to be replaced with a MockWelcomeServiceImpl

(3) Let's look at how to implement Spring's IOC. First of all, the WelcomeService will be managed by Spring:

<bean name="WelcomeService" class="XXX.XXX.XXX.service.impl.WelcomeServiceImpl"/>

(4) Then get the specific object through Spring IOC at the business code:

public class WelcomeController {

    @Autowired

    private WelcomeService service;

 

    @RequestMapping("/welcome")

    public String welcome() {

        return service.retrieveWelcomeMessage();

    }

}

(5) When testing, you only need to change the configuration file and change the corresponding implementation of WelcomeService to MockWelcomeServiceImpl:

<bean name="WelcomeService" class="XXX.XXX.XXX.service.impl.MockWelcomeServiceImpl"/>

 

There is no intrusion to the business code in this way, and it effectively realizes loose coupling.

 

Spring AOP

AOP (Aspect Oriented Programming) can encapsulate the logic or responsibilities (such as transaction processing, log management, access control, etc.) that are not related to the business but are called by the business modules, which is convenient to reduce the duplication of the system code and reduce the inter-module The degree of coupling is conducive to future scalability and maintainability.

 

AOP, aspect-oriented programming, is a supplement to OOP. A sentence read from the Internet: This kind of programming idea of ​​dynamically cutting the code into the specified method or location of the class at runtime is aspect-oriented programming. This is one of the ways, dynamically added at runtime. There is another way to switch the code to a specified method or location when compiling the code. This is a static addition method.

https://cxis.me/2017/04/12/Spring%E4%B8%ADAOP%E6%A6%82%E5%BF%B5%EF%BC%8C%E5%8E%9F%E7%90%86%EF%BC%8C%E5%BA%94%E7%94%A8%E4%BB%8B%E7%BB%8D/

 

Object Oriented Programming (English Object Oriented Programming), so it is also called OOP.

https://blog.csdn.net/q932104843/article/details/52298565

Guess you like

Origin blog.csdn.net/qq_42198024/article/details/107927093