Spring Boot
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
数据库相关
// ---------- Database ----------
// 添加 Spring Data JPA 的依赖
compile('org.springframework.boot:spring-boot-starter-data-jpa')
// 添加 MySQL 链接驱动的依赖
compile('mysql:mysql-connector-java:6.0.5')
// 添加 H2 的依赖
runtime('com.h2database:h2:1.4.193')
// ---------- Database ----------
数据库配置
# ---------- Database ----------
# DataSource
spring.datasource.url=jdbc:mysql://localhost:3306/databasename?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# JPA
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto=create-drop
# ---------- Database ----------
模板相关
// ---------- Template ----------
// 添加 Thymeleaf 的依赖
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
// ---------- Template ----------
Thymeleaf 配置
# ---------- Template ----------
# Thymeleaf 编码
spring.thymeleaf.encoding=UTF-8
# 热部署静态文件
spring.thymeleaf.cache=false
# 使用 HTML5 标准
spring.thymeleaf.mode=HTML5
# ---------- Template ----------
搜索相关
// ---------- Search ----------
// 添加 Spring Data ElasticSearch 的依赖
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')
// 添加 JNA 的依赖
compile('net.java.dev.jna:jna:4.3.0')
// ---------- Search ----------
Elasticsearch 配置
# ---------- Search ----------
# ElasticSearch 服务地址
spring.data.elasticsearch.cluster-nodes=localhost:9300
# 设置连接超时时间
spring.data.elesticsearch.properties.transport.tcp.connect_timeout=120s
# ---------- Search ----------
权限验证 安全相关
// ---------- Auth Manager ----------
// 添加 Spring Security 的依赖
compile('org.springframework.boot:spring-boot-starter-security')
// 添加 Thymeleaf Spring Security 的依赖
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.2.RELEASE')
// 添加 Spring Security 测试使用的依赖
testCompile('org.springframework.security:spring-security-test')
// ---------- Auth Manager ----------
文档生成相关
// ---------- 接口文档生成 Swagger2 ----------
compile('io.springfox:springfox-swagger2:2.7.0')
compile('io.springfox:springfox-swagger-ui:2.7.0')
// ---------- 接口文档生成 Swagger2 ----------
拦截器 过滤器 切片 相关
// ---------- AOP (Filter Interceptor Aspect) ----------
compile('org.springframework.boot:spring-boot-starter-aop:1.5.5.RELEASE')
// ---------- AOP (Filter Interceptor Aspect) ----------
Filter -> Interceptor -> ControllerAdvice -> Aspect -> Controller
社交网络相关
// ---------- 社交网络服务的抽象 ----------
compile("org.springframework.social:spring-social-config:1.1.6.RELEASE")
compile('org.springframework.social:spring-social-core:1.1.6.RELEASE')
compile('org.springframework.social:spring-social-security:1.1.6.RELEASE')
compile('org.springframework.social:spring-social-web:1.1.0.RELEASE')
// ---------- 社交网络服务的抽象 ----------
SpringBoot 热部署相关
// ---------- 配置 spring boot dev-tools 热部署 ----------
compile('org.springframework.boot:spring-boot-devtools:1.4.3.RELEASE')
// ---------- 配置 spring boot dev-tools 热部署 ----------
bootRun 配置
bootRun {
addResources = true
}
使用 gradle 的 bootRun 启动项目
其他
// 添加 Apache Commons Lang 的依赖
compile('org.apache.commons:commons-lang3:3.5')
// 添加 lombok 的依赖
compile('org.projectlombok:lombok:1.16.18')
// 添加 Json 的依赖
compile('com.alibaba:fastjson:1.2.46')
Gradle 配置文件示例
buildscript {
ext {
springBootVersion = '1.5.10.RELEASE'
}
// Thymeleaf 版本定义
ext['thymeleaf.version'] = '3.0.3.RELEASE'
ext['thymeleaf-layout-dialect.version'] = '2.2.0'
// Hibernate 版本定义
ext['hibernate.version'] = '5.2.15.Final'
repositories {
// mavenCentral()
maven {
url("http://maven.aliyun.com/nexus/content/groups/public/")
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.jytec.blog'
version = '0.0.1'
sourceCompatibility = 1.8
repositories {
// mavenCentral()
maven {
url("http://maven.aliyun.com/nexus/content/groups/public/")
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
// ---------- Database ----------
// 添加 Spring Data JPA 的依赖
compile('org.springframework.boot:spring-boot-starter-data-jpa')
// 添加 MySQL 链接驱动的依赖
compile('mysql:mysql-connector-java:6.0.5')
// 添加 H2 的依赖
runtime('com.h2database:h2:1.4.193')
// ---------- Database ----------
// ---------- Template ----------
// 添加 Thymeleaf 的依赖
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
// ---------- Template ----------
// ---------- Search ----------
// 添加 Spring Data ElasticSearch 的依赖
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')
// 添加 JNA 的依赖
compile('net.java.dev.jna:jna:4.3.0')
// ---------- Search ----------
// ---------- Auth Manager ----------
// 添加 Spring Security 的依赖
compile('org.springframework.boot:spring-boot-starter-security')
// 添加 Thymeleaf Spring Security 的依赖
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.2.RELEASE')
// ---------- Auth Manager ----------
// 添加 Apache Commons Lang 的依赖
compile('org.apache.commons:commons-lang3:3.5')
// 添加 lombok 的依赖
compile('org.projectlombok:lombok:1.16.18')
// 添加 Json 的依赖
compile('com.alibaba:fastjson:1.2.46')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
应用配置文件示例
# ---------- Template ----------
# Thymeleaf 编码
spring.thymeleaf.encoding=UTF-8
# 热部署静态文件
spring.thymeleaf.cache=false
# 使用 HTML5 标准
spring.thymeleaf.mode=HTML5
# ---------- Template ----------
# ---------- Database ----------
# 使用 H2 的控制台
spring.h2.console.enabled=true
# DataSource
spring.datasource.url=jdbc:mysql://localhost:3306/jyblog?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
spring.datasource.username=jyblog
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# JPA
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto=create-drop
# ---------- Database ----------
# ---------- Search ----------
# ElasticSearch 服务地址
# spring.data.elasticsearch.cluster-nodes=localhost:9300
# 设置连接超时时间
# spring.data.elesticsearch.properties.transport.tcp.connect_timeout=120s
# ---------- Search ----------