This is my fifth day of the August Challenge

This series of code address: github.com/HashZhang/s…

Source code file: github.com/HashZhang/s…

1. Dependencies required by log4J2 asynchronous logs: Exclude the default logs to implement logback, increase the dependencies on log4j2, and add disruptor dependencies required by log4J2 asynchronous logs.

<! <dependency> <groupId>org.springframework.boot</groupId> <artifactId> </artifactId> </artifactId> </artifactId> </artifactId> </artifactId> </artifactId> </artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> <! Log4j2 async log dependencies < <groupId>com.lmax</groupId> <artifactId>disruptor</artifactId> <version>${disruptor.version}</version> </dependency>Copy the code

2. Dependencies of javax.xml. Our project uses JDK 11. The modularized nature of the JDK after 9 causes javax.xml to not load automatically, so the following modules are required:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>${jaxb.version}</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>${jaxb.version}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>${jaxb.version}</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-xjc</artifactId>
    <version>${jaxb.version}</version>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>${activation.version}</version>
</dependency>
Copy the code

3. Use Junit5 for unit testing. To use Junit5, see Junit5 User Guide

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</dependency>
Copy the code

4. Use Spring Boot unit tests, see features. Testing

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
Copy the code

The Spring Boot unit tests already include mockito dependencies, but we also need the Mock Final class, so add the following dependencies:

<! - mockito extension, Mockito --> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-inline</artifactId> mockito-inline</artifactId> <version>${mokito.version}</version> <scope>test</scope> </dependency>Copy the code

6. Embedded Redis: Use Embedded Redis for unit tests involving Redis: If your unit tests require access to Redis, you need to initialize a Redis before testing and close it afterwards. Use Embedded – Redis. We’ve already added this dependency to the Spring-cloud-parent, so you can use it directly. Reference: embedded – redis

<dependency>
    <groupId>com.github.kstyrc</groupId>
    <artifactId>embedded-redis</artifactId>
    <version>${embedded-redis.version}</version>
    <scope>test</scope>
</dependency>
Copy the code

7. Sqlite unit test dependencies: For database unit tests, we can use SQLite. Reference: sqlite – JDBC

<dependency>
    <groupId>org.xerial</groupId>
    <artifactId>sqlite-jdbc</artifactId>
    <version>${sqlite-jdbc.version}</version>
    <scope>test</scope>
</dependency>
Copy the code

8. Specify the compile level to Java 11

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> The < version > 3.8.1 < / version > < configuration > < source > 11 < / source > <! --ingore javac compiler assert error--> <forceJavacCompilerUse>true</forceJavacCompilerUse> <target>11</target> </configuration> </plugin> </plugins> </build>Copy the code

Source code file: github.com/HashZhang/s…

The Spring-Framework-Common project, a common dependency that uses Spring and the Spring Boot framework, is a pure dependency project.

1. Adopt Caffeine for internal Cache frameworks: This is a highly efficient local Cache framework with the same interface design as Guava-Cache and can be easily upgraded. In terms of performance, Caffeine has been tested against guava-cache, ConcurrentHashMap, ElasticSearchMap, Collision and Ehcache implementations in the source code, and given to the Yahoo test library. The simulation approximates a real user scenario, and Caffeine uses a number of papers to implement caching for different scenarios, such as:

  1. Adaptive Replacement Cache: www.cs.cmu.edu/~15-440/REA…

2. Quadruply – segmented LRU:www.cs.cornell.edu/~qhuang/pap… 3. 2 Queue:www.tedunangst.com/flak/post/2… 4. Segmented LRU: www.is.kyusan-u.ac.jp/~chengk/pub… 5. Filtering – -based Buffer Cache: storageconference. Us / 2017 / cca shut…

For this reason, we chose Caffeine as our local cache framework (see caffeine)

<dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
</dependency>
Copy the code

2. Use Google’s Java development library Guava: Guava is Google’s Java library. Although we don’t use guava for local caching, there are many other elements of Guava that we use frequently. Reference: Guava docs

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>${guava.version}</version>
</dependency>
Copy the code

3. Use fastJSON for internal serialization: Note that json libraries generally need to be warmed up, which will be covered later. Reference: fastjson

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>${fastjson.version}</version>
</dependency>
Copy the code

4. Simplify code with Lombok. See ProjectLombok

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>
Copy the code

5. Invoke path record -sleuth. Reference: spring — cloud – sleuth

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
Copy the code

6. Cross-thread ThreadLocal. Reference: transmittable – thread – local

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>transmittable-thread-local</artifactId>
    <version>${transmittable-thread-local.version}</version>
</dependency>
Copy the code

7. Swagger Reference: swagger

<! --Swagger--> <! <groupId> <artifactId> springfox.swagger2 </artifactId> </artifactId> </artifactId> <version>${swagger.version}</version> </dependency> <! </groupId> </groupId> </artifactId> </artifactId> </artifactId> </artifactId> <version>${swagger.version}</version> </dependency>Copy the code

8. Apache Commons tool package. We’ll use some Commons toolkits to simplify the code:

  • commons-lang
  • commons-collections
  • commons-text
<! -- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <! -- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> <version>${commons-collections4.version}</version> </dependency> <! -- https://mvnrepository.com/artifact/org.apache.commons/commons-text --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-text</artifactId> <version>${commons-text.version}</version> </dependency>Copy the code

In this section we detail the parent for all of our projects and the design of the spring-Framework-Common dependencies for the toolkit that uses Spring and Spring Boot features. In the next section, we’ll look in detail at the dependencies that provide microservice features.

Wechat search “my programming cat” to follow the public account, every day, easy to improve technology, win a variety of offers: