This is the fourth day of my participation in the August More text Challenge. For details, see: August More Text Challenge

Function is introduced

As the name implies, this module is the core module in the Spirng Framewok and is required to support many spring functions. These include:

Submodule name Description information
org.springframework.asm Operations on Java’s own bytecode, described toJavaAgentYou should be familiar with this area
org.springframework.cglib Integrate dynamic proxy module
org.springframework.core The Core module of Spring itself is also the core module of the whole project
org.springframework.lang Annotate class modules
org.springframework.util Tool modules include: comparator, concurrency, XML and other tools
org.springframework.objenesis integrationobjenesisThe module

Third party dependence


dependencies {
   cglib("cglib:cglib:${cglibVersion}@jar") // Cglib dynamic proxy
   objenesis("org.objenesis:objenesis:${objenesisVersion}@jar") / / objenesis integration
   coroutines(project(path: ":kotlin-coroutines", configuration: 'classesOnlyElements'))
   compile(files(cglibRepackJar))
   compile(files(objenesisRepackJar))
   compile(project(":spring-jcl")) / / log
   compileOnly(project(":kotlin-coroutines"))
   compileOnly("io.projectreactor.tools:blockhound") / / Java agent/monitoring tool (https://github.com/reactor/BlockHound)
   optional("net.sf.jopt-simple:jopt-simple") // Command line parsing tool
   optional("org.aspectj:aspectjweaver") / / eclipse's http://www.eclipse.org/aspectj/
   optional("org.jetbrains.kotlin:kotlin-reflect")
   optional("org.jetbrains.kotlin:kotlin-stdlib")
   optional("io.projectreactor:reactor-core") // Non-blocking IO
   optional("io.reactivex:rxjava")  // Reactive Extension for Java
   optional("io.reactivex:rxjava-reactive-streams") // RxJava Streams operation
   optional("io.reactivex.rxjava2:rxjava") // Integrate rxJavA2 backwards
   optional("io.reactivex.rxjava3:rxjava") / / integration rxjava3
   optional("io.netty:netty-buffer") // NiO framework integration
   // Test is exclusive
   testCompile("io.projectreactor:reactor-test") // Reactor test package
   testCompile("com.google.code.findbugs:jsr305") // This is interesting. Use Google's FindBugs
   testCompile("javax.annotation:javax.annotation-api") // Some Java annotation apis, such as @postConstruct, @Resource, @predestroy, etc
   testCompile("javax.xml.bind:jaxb-api") / / XML
   testCompile("com.fasterxml.woodstox:woodstox-core") // Fast open source Xml processor that conforms to StAX(STreaming Api for Xml Processing) specification
   testCompile("org.xmlunit:xmlunit-assertj") // XML test related
   testCompile("org.xmlunit:xmlunit-matchers") // XML match correlation
   testCompile(project(":kotlin-coroutines"))
   testCompile("io.projectreactor.tools:blockhound")}Copy the code

From the third-party dependencies introduced above, dynamic proxies, JVM monitoring capabilities, support for command-line parsing, AOP, and responsive programming are used in the Spring-Core module. The test is xmlUnit related. Here’s a look at objecesis and skip the rest to focus on Spring itself.

objenesis

Here is the official introduction

Needing to instantiate an object without calling the constructor is a fairly specialized task, however there are certain cases when this is useful:Serialization, Remoting and Persistence – Objects need to be instantiated and restored to a specific state, without invoking code.Proxies, AOP Libraries and Mock Objects – Classes can be subclassed without needing to worry about the super() constructor.Container Frameworks – Objects can be dynamically instantiated in non-standard ways.

In simple terms, it is used to create specific objects. Main solution: Since not all classes have parameterless constructors or class constructors are private, in which case class.newInstance cannot be satisfied if we want to instantiate objects. Objenesis was born to solve these problems.

How it works: Objects are instantiated based on their type, JVM version, JVM vendor, and security manager. Objects are cached using ConcurrentHashMap, then added using putIfAbsent, and finally dynamically manipulated and instantiated using ASM bytecode.

public class TestInstance {

    public String name;

    private int x;
    private Integer y;

    public TestInstance(String name, int x, Integer y) {
        this.name = name;
        this.x = x;
        this.y = y;
    }

    public void print(a) {
        System.out.println("name = " + name);
        System.out.println("x = " + x);
        System.out.println("y = " + y);
    }

    public static void main(String[] args) {
        Objenesis objenesis = new ObjenesisStd(true);
        TestInstance test = objenesis.newInstance(TestInstance.class);
        test.print();
        System.out.println("= = = = = = = = = = =");
        TestInstance testInstance = new TestInstance("new".1.null); testInstance.print(); }}Copy the code

Then spring what to do with it, it is to implement the Objenesis interface, and USES ConcurrentReferenceHashMap caching processing, application and dynamic proxy aop, spring – the context and spirng – web modules are involved.