Selection of actual development technology for SpringBoot project

Posted by alan543 on Thu, 20 Jan 2022 13:03:54 +0100

springboot project is a popular java web project. This paper mainly describes the technical selection of the project. This experience has been applied and verified in actual combat. It is quite stable in the production environment (centos7) and has strong scalability. For example, it is very simple to expand redis, mongodb and other cache technologies in the later stage, as well as spring related technologies.

The most important aspects of technology selection are: development cost (including learning, use and code reading cost) and stability in production environment

springboot version: 2.2.5.0 RELEASE

With the upgrade of the springboot version, in actual combat, 1 x. There are great differences between versions 2.0 ~ 2.1 and above 2.2. Versions after 2.2 will not affect the compatibility of new technologies. At the same time, they can be better compatible with various features and plug-ins of the new version of spring cloud-- springboot2.2 Hoxton that can support spring cloud SR3 also supports springAdmin (version 2.2.1, supporting Chinese internationalization).

Container: undertow

The built-in container of boot is tomcat, but after local use test and long-term observation in the production environment, the performance is not as good as that of undertow. I believe we can find a lot of information about the performance comparison between the two containers. Here, only based on practical experience, undertow is better than Tomcat.

Template engine: Beetle 1.2.14 RELEASE ( Document portal)

thymeleaf comes with boot. This technology is very popular abroad, but jsp is more popular in China. jsp is a scripting language, which is very popular and excellent in the era of springMvc. However, it is too heavily used in the lightweight architecture of boot, so it hesitates to choose beetle. I contacted FrameMaker very early in development, and I love and hate template engine, What I love is the excellent performance, but what I hate is the poor readability. The template file is messy and not developed by myself. I can't understand it without some effort. Beetle not only has the performance of FrameMaker, but also has the readability of html and is compatible with the el expression of jsp Great

Data persistence: beetsql 1.2.14 RELEASE ( Document portal)

There are two sets of cores for data persistence in the market: ORM(hibernate, JPA) and JDBC (mybatis). Of course, they can be interconnected, but it is still troublesome to use them explicitly. mybatis pubs version enhances ORM on the basis of mybatis, but it is not as easy to use as BeetSql, which takes care of both sides at the beginning of design

json tool: fastjson 1.2.73

As for json tools, boot comes with jackjson. There are different opinions on which is better. In terms of use, they are almost the same, because they only focus on the bottom line of performance, the ability of serialization and the convenience of development

pom files are as follows:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ds</groupId>
  <artifactId>sboot-demo</artifactId>	<!-- entry name -->
  <version>0.0.1</version> 					<!-- Packaged version -->
  <packaging>jar</packaging>			<!-- Packaging method -->
  <!-- springboot edition,introduce spring The package does not need to specify a version, but will be imported in this version compatibility mode -->
  <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.5.RELEASE</version>
		<relativePath />
	</parent>
	<!--dependencies Import package area  -->
	<dependencies>
		<!-- structure web Apply, eliminate embedded tomcat -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-tomcat</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<!-- use undertow High performance web Server, replacing tomcat -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-undertow</artifactId>
		</dependency>
		<!-- integrate beetl,Contains beetle and beetlsql -->
		<dependency>
			<groupId>com.ibeetl</groupId>
			<artifactId>beetl-framework-starter</artifactId>
			<version>1.2.14.RELEASE</version>
		</dependency>
		<!-- Automatic assembly, data source, operation database -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>com.zaxxer</groupId>
			<artifactId>HikariCP</artifactId>
		</dependency>
		<!-- You may not configure the version here, but you need to pay attention to yourself mysql Version of, 5.5 The following best configuration versions,
		The latest version of driver, required mysql At 5.7 And above, and the drive path in the configuration file also changes-->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.37</version>
		</dependency>
		<!-- Simple operation json -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.73</version>
		</dependency>
		<!--apache Tools, there are many tools that are easy to use, such as StringUutils  -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>
		<!-- Easy to use entity class getset And construction method; slf4j Output log -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<scope>provided</scope>
		</dependency>
		<!-- test test -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<!-- devtool Hot deployment -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
			<scope>true</scope>
		</dependency>
	</dependencies>
	<!-- build As the name suggests, it is a project creation configuration -->
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<target>1.8</target>
					<source>1.8</source>
					<encoding>UTF-8</encoding>
					<compilerArgs>
						<arg>-parameters</arg>
					</compilerArgs>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<fork>true</fork>
					<!--Here, only program files are packaged, not dependencies jar,The final generated jar Bag for slimming -->
					<layout>ZIP</layout>
					<includes>
						<include>
							<groupId>com.ds</groupId>
							<artifactId>sboot-demo</artifactId>
						</include>
					</includes>
					<!--If you want to get dependence jar,You can regenerate the program comments -->
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

Topics: Java Maven Spring Boot