前言:springboot项目是当前流行的java web项目,本篇主要针对项目的技术选型进行说明。此经验在实战中应用和检验过,在生产环境(centos7)下相当稳定,且扩展性强,比如后期扩展redis,mongodb等缓存技术,以及spring相关技术都很简单。
技术选型最重要的是:开发代价(包括学习,使用和代码阅读代价),生产环境下的稳定性
springboot版本:2.2.5.RELEASE
随着springboot版本的升级,就实战中来看,1.x,2.0~2.1,2.2以上版本有较大区别,2.2之后的版本并不会影响新技术的兼容,同时能更好的兼容springcloud的新版本的各种特性及插件。--springboot2.2能支撑springcloud的Hoxton.SR3,同时对springAdmin(2.2.1版本,支持中文国际化)也有很好支持。
容器:undertow
boot自带的内置容器是tomcat,但是经本地使用测试和生产环境长期观察,并没有undertow的性能好,关于两个容器的性能比较,相信可以找到很多资料,这里只以实践经验来说,undertow更优于tomcat。
模板引擎:Beetle 1.2.14.RELEASE (文档传送门)
boot自带的是thymeleaf,这种技术在国外很流行,但是国内更流行的是jsp,jsp属于脚本语言,在springMvc时代很流行且应用极好,但是在boot这种轻量级架构中使用太重,所以犹豫再三还是选择了beetle,在很早开发的时候接触过framemarker,对于模板引擎是又爱又恨,爱的是性能很棒,恨的是可读性极差,那模板文件乱糟糟的,不是自己开发的不花点功夫真看不懂,beetle既有framemarker的性能,同时拥有html的可读性,还兼容了jsp的el表达式.超赞.
数据持久化:BeetSql 1.2.14.RELEASE (文档传送门)
数据持久化市面上有两套核心:ORM(hibernate,JPA),jdbc(mybatis),当然都可以互通,但显式使用还是很麻烦,mybatis pubs版本在mybatis的基础上增强了ORM,但是还是没有BeetSql这种在设计之初就照顾到双方的技术好用.
json工具:fastjson 1.2.73
关于json工具,boot自带的是jackjson,关于哪种好,众说纷纭,就使用而言,都差不多,因为只关注性能的底线,序列化的能力和开发是否方便.
pom文件如下:
<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> <!-- 项目名称 -->
<version>0.0.1</version> <!-- 打包版本 -->
<packaging>jar</packaging> <!-- 打包方式 -->
<!-- springboot版本,引入spring的包不用指定版本,会以此版本兼容模式引入 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath />
</parent>
<!--dependencies引入包区域 -->
<dependencies>
<!-- 构建web应用,剔除内嵌的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>
<!-- 使用undertow高性能web服务器,取代tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<!-- 集成beetl,包含了beetle和beetlsql -->
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl-framework-starter</artifactId>
<version>1.2.14.RELEASE</version>
</dependency>
<!-- 自动装配数据源,操作数据库 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<!-- 此处可不配置版本,但是需要注意自己mysql的版本,5.5以下最好配置版本,
最新版本驱动,需要mysql在5.7及以上,同时配置文件中的驱动路径也有变化-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
</dependency>
<!-- 简便操作json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.73</version>
</dependency>
<!--apache工具,有很多工具很好用,比如 StringUutils -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- 简便使用实体类getset和构造方法;slf4j输出日志 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- test测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- devtool热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
</dependencies>
<!-- build 顾名思义,是工程创建配置 -->
<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>
<!--这里只打包程序文件,不打包依赖jar,可对最终生成的jar包进行瘦身 -->
<layout>ZIP</layout>
<includes>
<include>
<groupId>com.ds</groupId>
<artifactId>sboot-demo</artifactId>
</include>
</includes>
<!--若想获得依赖jar,可把此段程序注释再生成即可 -->
</configuration>
</plugin>
</plugins>
</build>
</project>