Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

Netkiller Spring Cloud 手札

Spring Cloud Cookbook(2024版)

Mr. Neo Chan, 陈景峯(BG7NYT)



中国广东省深圳市望海路半岛城邦三期
518067
+86 13113668890


$Id: book.xml 606 2013-05-29 09:52:58Z netkiller $

电子书最近一次更新于 2024-11-01 20:53:45

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

http://www.netkiller.cn
http://netkiller.github.io
http://netkiller.sourceforge.net
微信公众号: netkiller
微信:13113668890 请注明“读者”
QQ:13721218 请注明“读者”
QQ群:128659835 请注明“读者”
知乎专栏

2017-11


致读者

Netkiller 系列手札 已经被 Github 收录,并备份保存在北极地下250米深的代码库中,备份会保留1000年。

Preserving open source software for future generations

The world is powered by open source software. It is a hidden cornerstone of modern civilization, and the shared heritage of all humanity.

The GitHub Arctic Code Vault is a data repository preserved in the Arctic World Archive (AWA), a very-long-term archival facility 250 meters deep in the permafrost of an Arctic mountain.

We are collaborating with the Bodleian Library in Oxford, the Bibliotheca Alexandrina in Egypt, and Stanford Libraries in California to store copies of 17,000 of GitHub’s most popular and most-depended-upon projects—open source’s “greatest hits”—in their archives, in museum-quality cases, to preserve them for future generations.

https://archiveprogram.github.com/arctic-vault/

目录

1. 自述
1.1. 写给读者
1.2. 作者简介
1.3. 如何获得文档
1.4. 打赏(Donations)
1.5. 联系方式
I. Spring Boot
1. Spring Boot Quick start
1.1. 创建项目
1.2. pom.xml
1.3. Controller
1.4. Springboot with Maven
1.4.1. resource
1.4.2. Maven run
1.4.3. Spring Boot maven 插件 build-image
1.4.4. 生成项目信息
2. Spring 开发环境
2.1. Java 开发环境
2.2. 安装 Spring Tool Suite
2.3. Dashboard
2.4. Spring Initializr - Bootstrap your application
3. SpringApplication
3.1. 运行 Spring boot 项目
3.1.1. Linux systemd
3.1.2. 传统 init.d 脚本
3.1.3. 编译用于Tomcat的 War
3.2. @SpringBootApplication
3.2.1. 排除 @EnableAutoConfiguration 加载项
3.3. 获取 Resources 目录中的静态文件
3.4. @EnableAutoConfiguration
3.5. @ComponentScan
3.6. @EntityScan 实体扫描
3.7. @EnableJpaRepositories
3.8. 启动和销毁
3.9. 打印环境变量
3.10. CharacterEncodingFilter
3.11. 隐藏 Banner
3.12. 实体与仓库扫描
3.13. 列出 Beans
3.14. Tomcat 端口
3.15. 配置项设定
3.16. spring.profiles.active
3.17. @Profile("dev") / @ActiveProfiles("dev")
3.18. 设置默认时区
4. 如何优雅停止 Springboot 运行
4.1. 准备工作
4.2. kill 命令演示
4.3. 容器中如何优雅关闭 Springboot
4.4. 写入PID文件
5. Properties 配置文件
5.1. application.properties 配置文件
5.1.1. application.properties 参考
5.1.2. 启动指定参数
5.1.3. 加载排除
5.1.4. PID FILE
5.1.5. banner 关闭
5.1.6. server
5.1.7. logging
5.1.8. 内嵌 tomcat server
5.1.9. servlet
5.1.10. JSON 输出与日期格式化
5.1.11. SMTP 相关配置
5.1.12. Redis
5.1.13. MongoDB
5.1.14. MySQL
5.1.15. Oracle
5.1.16. default_schema
5.1.17. datasource
5.1.18. velocity
5.1.19. Security 相关配置
5.1.20. MVC 配置
5.1.21. Kafka 相关配置
5.2. Properties 文件
5.2.1. @Value 注解
5.2.2. @EnableConfigurationProperties 引用自定义 *.properties 配置文件
5.2.3. @PropertySource 注解载入 properties 文件
5.3. Environment 读取配置文件
5.4. 手工载入 *.properties 文件
5.4.1. 家在 resources 目录中的指定文件
5.4.2. 从 InputStreamReader 打开 application.properties
5.5. 命令行注入配置项
5.5.1. spring.profiles.active 参数切换配置文件
5.5.2. SpringApplicationBuilder.properties() 方法添加配置项
5.5.3. 禁用命令行注入环境变量
5.6. PropertyResolver 获取配置
5.7. 参数引用
5.8. 默认值
5.9. 产生随机数
5.9.1. 随机数
5.10. 多行字符串
5.11. 注入多值属性 arrays, list, set
5.12. List 列表类型
5.13. Map类型
5.14. Binder
5.15. 加密 application.properties 中的敏感内容
6. Spring boot with Logging
6.1. 配置日志文件
6.1.1. 日志输出级别
6.1.2. Spring boot 2.1 以后的版本不打印 Mapped 日志问题
6.1.3. 禁止控制台输出日志
6.1.4. 定制日志格式
6.1.5. 彩色输出
6.2. 打印日志
6.2.1. lombok
6.3. logback 配置详解
6.3.1. 标准输出
6.3.2. 禁止 logback 日志输出
6.3.3. 指定Class过滤日志
6.3.4. configuration 属性配置
6.3.5. contextName 设置上下文名称
6.3.6. property 设置变量
6.3.7. encoder 日志格式设置
6.3.8. RollingFileAppender
6.3.9. 日志过滤
6.3.10. 标准输出
6.3.11. MDC
6.3.12. 日志写入 MongoDB
6.3.13. 日志发送给 logstash
6.3.14. fluentd
6.3.15. Loki4j Logback
6.4. Log4j2 + Gelf + Logstash
6.4.1. Maven 配置
6.4.2. log4j2.xml 配置
6.4.3. Java 测试代码
6.4.4. Logstash 配置
6.4.5. 测试结果
6.4.6. Log4j2 更多技巧
6.5. 日志报警
6.5.1. Logstash 配置
6.5.2. 监控 SpringBootApplication 的启动和退出
6.6. Spring boot with ELK(Elasticsearch + Logstash + Kibana)
6.6.1. TCP 方案
6.6.2. Redis 方案
6.6.3. Kafka 方案
6.6.4. Other
7. Spring boot with Undertow
7.1. Maven 依赖
7.2. Application
7.3. 相关配置
8. Spring boot with Jetty
9. Spring boot with HTTP2 SSL
9.1. 生成自签名证书
9.2. application.properties 配置文件
9.3. 启动 Spring boot
9.4. restTemplate 调用实例
9.5. HTTP2
10. Spring boot with MongoDB
10.1. Maven
10.2. Application
10.3. MongoTemplate
10.4. Repository
11. Spring boot with MySQL
11.1. Maven
11.2. Resource
11.3. Application
11.4. JdbcTemplate
11.5. CrudRepository
12. Spring boot with Oracle
12.1. Maven
12.2. application.properties
12.3. Application
12.4. CrudRepository
12.5. JdbcTemplate
12.6. Controller
13. Spring boot with PostgreSQL
13.1. pom.xml
13.2. application.properties
13.3. Application
13.4. CrudRepository
13.5. JdbcTemplate
13.6. Controller
13.7. Test
14. Spring boot with Elasticsearch
14.1. Maven
14.2. Application
14.3. application.properties
14.4. Domain
14.5. ElasticsearchRepository
15. Spring boot with Elasticsearch TransportClient
15.1. Maven
15.2. Application
15.3. application.properties
15.4. ElasticsearchConfiguration
15.5. RestController
16. Spring boot with Apache Hive
16.1. Maven
16.2. application.properties
16.3. Configuration
16.4. CURD 操作实例
17. Spring boot with Phoenix
17.1. Maven
17.2. application.properties
17.3. Configuration
18. Spring boot with Datasource
18.1. Master / Slave 主从数据库数据源配置
18.1.1. application.properties
18.1.2. 配置主从数据源
18.1.3. 选择数据源
18.2. 多数据源配置
18.3. JPA 多数据源
19. 连接池配置
19.1. org.apache.tomcat.jdbc.pool.DataSource
19.2. druid
19.2.1. 加密数据库密码
19.3. c3p0 - JDBC3 Connection and Statement Pooling
19.4. dbcp2
19.5. bonecp
19.6. HikariPool
20. Spring boot with Queue
20.1. Spring boot with RabbitMQ(AMQP)
20.1.1. maven
20.1.2. RabbitMQConfig
20.1.3. 生产者
20.1.4. 消费者
20.2. Spring boot with Apache Kafka
20.2.1. 安装 kafka
20.2.2. maven
20.2.3. Spring boot Application
20.2.4. EnableKafka
20.2.5. KafkaListener
20.2.6. 测试
20.2.7. 完整的发布订阅实例
20.2.8. Spring cloud with Kafka
21. Spring boot with Scheduling
21.1. 启用计划任务
21.1.1. Application.java
21.1.2. 配置
21.1.3. Component
21.2. 计划任务控制开关
21.3. @Scheduled 详解
21.3.1. fixedRate 案例
21.3.2. timeUnit
21.4. cron 表达式
21.4.1. 每3秒钟一运行一次
21.4.2. 凌晨23点运行
21.4.3. 周一 ~ 周五
21.5. Timer 例子
21.6. ScheduledExecutorService 例子
22. Spring boot with Swagger
22.1. Spring boot with Springdoc
22.1.1. WebMvc
22.1.2. Webflux
22.1.3. Swagger UI
22.1.4. 从 SpringFox 迁移到 Swagger3 注解变化
22.2. Spring boot with knife4j
22.2.1. maven
22.2.2. Knife4jConfiguration
22.2.3. application.properties
22.3. springfox
22.3.1. Swagger3
22.3.2. Swagger2
22.3.3. @Api() 资源定义
22.3.4. @ApiIgnore 忽律接口
22.3.5. @ApiOperation()
22.3.6. @ApiResponses
22.3.7. @ApiModel 实体类
23. Spring boot with lombok
23.1. @Builder
23.2. @Slf4j 注解
24. Spring boot with Container
24.1. Spring boot with Docker
24.1.1. 通过 Docker 命令构建镜像
24.1.2. 通过 Maven 构建 Docker 镜像
24.1.3. [ERROR] No plugin found for prefix 'dockerfile' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/neo/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
24.1.4. curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:8888
24.2. Spring boot with Docker stack
24.2.1. 编译 Docker 镜像
24.2.2.
24.3. Spring boot with Kubernetes
24.3.1. Kubernetes 编排脚本
24.3.2. 部署镜像
25. Spring boot with command line
25.1. Maven
25.2. CommandLineRunner 例子
25.3. ApplicationRunner 例子
26. Spring Boot Actuator
26.1. Maven 依赖
26.2. 与 Spring Boot Actuator 有关的配置
26.2.1. 禁用HTTP端点
26.2.2. 安全配置
26.2.3. 修改 actuator 地址
26.2.4. 关机
26.3. actuator 接口
26.4. 健康状态
26.4.1. 健康状态
26.5. info 配置信息
26.6. beans 信息
26.7. caches
26.8. conditions
26.9. configprops 配置文件
26.10. env 环境变量
26.11. logfile 日志
26.12. threaddump 线程信息
26.13. 计划任务
26.14. metrics
26.15. 控制器映射 URL
26.16. 自定义监控指标
27. SpringBootTest
27.1. Maven 依赖
27.2. 测试类
27.2.1. Junit基本注解介绍
27.3.
27.3.1. Assert.assertEquals 判断相等
27.3.2. Assert.assertTrue
27.4. JPA 测试
27.5. TestRestTemplate
27.6. Controller单元测试
27.7. WebTestClient
28. Spring boot with Aop
28.1. Aspect
28.1.1. Maven
28.1.2. Pojo 类
28.1.3. Service 类
28.1.4. Aspect 类
28.1.5. 控制器
28.1.6. Application
28.1.7. 测试
29. Spring boot with starter
29.1. 实现 starter
29.1.1. Maven pom.xml 依赖包
29.1.2. 配置文件处理
29.1.3. 自动配置文件
29.1.4. 启用 starter 的自定义注解
29.2. 引用 starter
29.2.1. Maven pom.xml 引入依赖
29.2.2. 通过注解配置 starter
29.2.3. 测试运行结果
30. Spring boot with Monitor
30.1. Spring boot with Grafana
30.1.1. Springboot 集成 InfluxDB
30.1.2. InfluxDB
30.2. Spring Boot with Prometheus
30.2.1. Maven 依赖
30.2.2. application.properties 配置文件
30.2.3. 启动类
30.2.4. 测试
30.2.5. 控制器监控
30.2.6. 自定义埋点监控
32. Spring boot with Git version
32.1. CommonRestController 公共控制器
32.2. VersionRestController 测试控制器
32.3. 创建 .gitattributes 文件
33. Spring boot with Session share
33.1. Redis
33.1.1. Maven
33.1.2. application.properties
33.1.3. Application
33.2. 测试 Session
33.3. JDBC
33.4. Springboot 2.1
34. Spring boot with Caching
34.1. maven
34.1.1. Redis
34.2. 启用缓存 @EnableCaching
34.3. 设置缓存 @Cacheable
34.3.1. 多参数处理
34.3.2. 对象参数
34.3.3.
34.3.4. 参数索引
34.3.5. 自动生成 key
34.3.6. SpEL表达式
34.3.7. 排除 null 结果
34.3.8. 排除 empty
34.4. 更新缓存 @CachePut
34.5. 删除缓存 @CacheEvict
34.6. 组合操作 @Caching
34.7. 解决Expire 和 TTL 过期时间
34.8. Cannot serialize
35. Spring boot with Email
35.1. Maven
35.2. Resource
35.3. POJO
35.4. RestController
35.5. Test
36. Spring boot with Hessian
36.1. Maven
36.2. Application
36.3. HessianServiceExporter
36.4. Service
36.5. RestController
37. Spring boot with Async
37.1. Callable 实现异步
37.2. WebAsyncTask 实现异步
37.3. DeferredResult 实现异步返回结果
37.4. 带有返回值的异步任务
37.4.1. Future
37.4.2. CompletableFuture
37.5. 默认简单线程池 SimpleAsyncTaskExecutor
37.5.1. 配置线程池
37.5.2. @Service/@Component 中异步执行
37.5.3. applicationTaskExecutor
37.6. ThreadPoolTaskExecutor 自定义线程池
37.6.1. 最简单的配置
37.6.2. 队列
37.6.3. 定义多个线程池
37.6.4. 实现 AsyncConfigurer 接口方式创建自定义连接池
37.6.5. 继承 AsyncConfigurerSupport 创建自定义连接池
37.6.6. 生产环境完整代码 @Bean 注入方式
37.6.7. 通过 @Bean 覆盖掉 SimpleAsyncTaskExecutor
37.7. 自定义线程池 ThreadPoolExecutor
37.7.1. ThreadPoolExecutor
37.7.2. 注入自定义线程池bean
37.8. 设置线程名称
37.9. 线程池监控
37.10. 注意事项
38. Springboot with Ethereum (web3j)
38.1. Maven
38.2. application.properties
38.3. TestRestController
38.4. 测试
39. Java Record 新特性
39.1. Record 替代 POJO 类
39.2. Record 作为 Properties
39.3. Record 作为实体类
39.4. Record 作为 Service
39.5. Record 作为 Controller
II. Spring Framework
40. Spring 框架
40.1. @Bean
40.1.1. @Scope 定义类型
40.1.2. InitializingBean
40.2. URL 拼装/解析
40.3. ServletUriComponentsBuilder
40.4. URL 路径相关
41. Spring MVC
41.1. @EnableWebMvc
41.1.1. CORS 跨域请求
41.1.2. Spring MVC CORS with WebMvcConfigurerAdapter
41.2. @Controller
41.2.1. @RequestMapping
41.2.2. @GetMapping
41.2.3. @PostMapping
41.2.4. @RequestBody
41.2.5. RequestMapping with Request Parameters - @RequestParam
41.2.6. @RequestHeader - 获取 HTTP Header 信息
41.2.7. RequestMapping with Path Variables - @PathVariable
41.2.8. @MatrixVariable注解,RFC3986定义URI的路径(Path)中可包含name-value片段
41.2.9. @ModelAttribute
41.2.10. @ResponseBody
41.2.11. @ResponseStatus 设置 HTTP 状态
41.2.12. @CrossOrigin
41.2.13. @CookieValue - 获取 Cookie 值
41.2.14. @SessionAttributes
41.2.15. ModelAndView
41.2.16. HttpServletRequest / HttpServletResponse
41.3. @RestController
41.3.1. 接口设计中 URL 参数,FORM 参数,JSON 怎么选择
41.3.2. 返回迭代器
41.3.3. 上传文件
41.3.4. 返回实体
41.3.5. JSON
41.3.6. 处理原始 RAW JSON 数据
41.3.7. 返回 JSON 对象 NULL 专为 "" 字符串
41.3.8. XML
41.3.9. 兼容传统 json 接口
41.3.10. 上传文件
41.3.11. Spring boot with csv
41.3.12. Json 处理
41.3.13. synchronized
41.3.14. Spring boot with Emitter
41.4. View
41.4.1. 配置静态文件目录
41.4.2. 添加静态文件目录
41.4.3. Using Spring’s form tag library
41.4.4. Thymeleaf
41.4.5. FreeMarker
41.4.6. i18n 国际化
41.5. Spring boot with Webpage
41.5.1. Maven
41.5.2. application.properties
41.5.3. Application
41.5.4. IndexController
41.5.5. src/main/webapp/WEB-INF/jsp/index.jsp
41.5.6. 集成模板引擎
41.6. Spring boot with Velocity template
41.6.1. Maven
41.6.2. Resource
41.6.3. Application
41.6.4. RestController
41.6.5. Test
41.7. Spring boot with Thymeleaf
41.7.1. Maven
41.7.2. application.properties
41.7.3. Controller
41.7.4. HTML5 Template
41.8. 校验器(Validator)
41.8.1. 常规用法
41.8.2. 自定义注解
41.9. Interceptor/Filter 拦截器/过滤
41.9.1. Session 拦截
41.9.2. Token 拦截
41.9.3. 过滤器
41.9.4. 拦截器获取PathVariable变量
41.10. String boot with RestTemplate
41.10.1. RestTemplate Example
41.10.2. GET 操作
41.10.3. POST 操作
41.10.4. PUT 操作
41.10.5. Delete 操作
41.10.6. 上传文件
41.10.7. HTTP Auth
41.10.8. PKCS12
41.10.9. Timeout 超时设置
41.11. RestClient
41.11.1. 创建 RestClient
41.11.2. Get 操作
41.11.3. Post Json
41.11.4. HTTP Authorization Basic
41.11.5. onStatus
41.11.6. Timeout 超时设置
41.11.7. 下载二进制流
43. WebFlux framework
43.1. Getting Started
43.1.1. Maven
43.1.2. Application
43.1.3. RestController
43.1.4. 测试
43.2. WebFlux 与 SprintMVC 有什么不同?
43.2.1. 实验程序
43.2.2. 实验结果
43.3. WebFlux Router
43.3.1. Component 原件
43.3.2. 路由配置
43.4. RestController
43.4.1. Post 数据
43.4.2. Thymeleaf
43.5. Webflux Redis
43.5.1. Maven Redis 依赖
43.5.2. Redis 配置
43.5.3. Config
43.5.4. Service
43.5.5.
43.6. Webflux Mongdb
43.6.1. Maven 依赖
43.6.2. Repository
43.6.3. Service
43.6.4. 控制器
43.7. Mono
43.7.1. Mono.just()/Mono.justOrEmpty()
43.7.2. MonoSink 创建 Mono
43.7.3. Supplier 创建 Mono
43.7.4. then()
43.7.5. 异常处理
43.7.6. 同步阻塞等待结果
43.8. Flux 返回多条数据
43.8.1. FluxSink 创建异步 Flux
43.8.2. SynchronousSink 创建同步 Flux
43.8.3. just()
43.8.4. 从 Flux/Mono 创建 Flux
43.8.5. 消息订阅
43.8.6. 从 Flux/Mono 创建 Flux
43.8.7. 从 Iterable 创建 Flux
43.8.8. 从 Stream 创建 Flux
43.8.9. defer()
43.8.10. Flux.interval()
43.8.11. Flux.empty()
43.8.12. Flux.error()
43.8.13. Flux.never()
43.8.14. Flux.range()
43.8.15. 返回数据
43.8.16. 持续更新 Flux
43.8.17. map(), flatMap()
43.8.18. 过滤
43.8.19. 触发操作
43.9. SSE
43.9.1. 一次性事件
43.9.2. 从 Steam 返回数据
43.9.3. 周期性事件
43.9.4. 返回 ServerSentEvent 数据结构
43.9.5. SSE 完整的例子
43.9.6. SSE Client 订阅实例
43.10. 并发
43.11. ConnectableFlux
43.12. WebClient
43.12.1. 配置 WebClient
43.12.2. @Controller/@RestController 实例
43.12.3. Get 请求实例
43.12.4. URI 参数
43.12.5. 查询参数
43.12.6. Post 操作演示
43.12.7. Post 表单数据
43.12.8. 上传文件
43.12.9. 设置 HTTP 头
43.12.10. 同步阻塞等待返回结果
43.12.11. websocket
43.12.12. 获取 HTTP 链接状态
43.12.13. Http Base Authentication - 401 Unauthorized
43.12.14. 订阅 SSE
43.12.15. 超时时间
43.12.16. share() 共享订阅数据
43.12.17. 打印调试日志
43.12.18. org.springframework.web.context.request.async.AsyncRequestNotUsableException: ServletOutputStream failed to flush: java.io.IOException: Broken pipe
43.13. Webflux 安全
43.13.1. Token 拦截器
43.13.2. JWT
43.13.3. spring-boot-starter-security
43.14. 常见问题
43.14.1. The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, e.g. via @EnableWebMvc and @EnableWebFlux, in the same application.
43.14.2. @EnableWebFluxSecurity 与 @EnableReactiveMethodSecurity 不生效
43.14.3. webflux netty 不支持 Content-Type: application/x-www-form-urlencoded
44. Service
44.1. Application
44.2. 定义接口
44.3. 实现接口
44.4. 调用 Service
44.5. context.getBean 调用 Service
44.6. AopContext
44.7. Service 单例/多例模式
44.7.1. Service 是单例模式
44.7.2. Service 多例实现
44.8. 构造方法
45. Tomcat Spring 运行环境
45.1. Maven
45.2. Spring MVC configuration
45.3. Tomcat
45.4. 集成 Mybatis
45.4.1. pom.xml
45.4.2. properties
45.4.3. dataSource
45.4.4. SqlSessionFactory
45.4.5. Mapper 扫描
45.4.6. Mapper 单一class映射
45.4.7. Service
45.4.8. 测试实例
III. Spring Data
46. EntityManager
47. Spring Data with JdbcTemplate
47.1. execute
47.2. queryForInt
47.3. queryForLong
47.4. queryForObject
47.4.1. 返回整形与字符型
47.4.2. 查询 Double 类型数据库
47.4.3. 返回日期
47.4.4. 返回结果集
47.4.5. 通过 "?" 向SQL传递参数
47.4.6. RowMapper 记录映射
47.5. queryForList
47.5.1. Iterator 用法
47.5.2. for 循环
47.5.3. forEach 用法
47.6. queryForMap
47.7. query
47.7.1. ResultSet
47.7.2. ResultSetExtractor
47.7.3. RowMapper
47.8. queryForRowSet
47.9. update
47.10. MapSqlParameterSource
47.11. 实例参考
47.11.1. 参数传递技巧
48. Spring Data with MySQL
48.1. 选择数据库表引擎
48.2. 声明实体
48.2.1. @Entity 声明实体
48.2.2. @Table 定义表名
48.2.3. @Id 定义主键
48.2.4. @Column 定义字段:
48.2.5. 非数据库字段
48.2.6. @Lob 注解属性将被持久化为 Blog 或 Clob 类型
48.2.7. @NotNull 不能为空声明
48.2.8. @Temporal 日期定义
48.2.9. 创建日期
48.2.10. @DateTimeFormat 处理日期时间格式
48.2.11. Enum 枚举数据类型
48.2.12. SET 数据结构
48.2.13. JSON 数据类型
48.2.14. 嵌入
48.2.15. @JsonIgnore
48.2.16. @EnableJpaAuditing 开启 JPA 审计功能
48.2.17. 注释 @Comment
48.2.18. @Pattern 数据匹配
48.2.19. 实体继承
48.3. 映射集合属性
48.3.1. List 集合
48.3.2. 数组集合
48.3.3. Map 集合
48.3.4. Set 集合
48.3.5. 外键名称
48.3.6. 集合表子查询
48.4. 外键
48.4.1. @JoinColumn
48.4.2. @OneToOne
48.4.3. OneToMany 一对多
48.4.4. ManyToMany 多对多
48.4.5. 外键级联删除
48.4.6. 外键级联操作
48.4.7. @JoinTable
48.4.8. @OrderBy
48.4.9. @JsonIgnoreProperties
48.4.10. 允许外键为 NULL
48.4.11. 只要外键,不要数据结构
48.5. 索引
48.5.1. 普通索引
48.5.2. 组合索引
48.5.3. 唯一索引
48.6. Repository
48.6.1. JpaRepository
48.6.2. CrudRepository
48.6.3. PagingAndSortingRepository
48.6.4. findByXXX
48.6.5. count 操作
48.6.6. delete 删除操作
48.6.7. IsNull
48.6.8. In/NotIn
48.6.9. TRUE / FALSE
48.6.10. Before/After
48.6.11. OrderBy
48.6.12. GreaterThan
48.6.13. Sort 排序操作操作
48.6.14. Pageable 翻页操作
48.6.15. @DynamicInsert 与 @DynamicUpdate
48.6.16. 继承已存在的 Repository
48.6.17. 自定义返回字段
48.7. TransactionTemplate
48.8. JPQL @Query
48.8.1. @Modifying 更新/删除
48.8.2. 参数传递
48.8.3. 原生 SQL 操作
48.8.4. @Query 与 Pageagble
48.8.5. 返回指定字段
48.8.6. 返回指定的模型
48.8.7. 通过定义接口,返回指定字段
48.8.8. 修改返回数据
48.8.9. 事务 @Transactional
48.8.10. IN / NOT 子查询
48.9. FAQ 常见问题
48.9.1. Could not write JSON: failed to lazily initialize a collection of role
48.9.2. Query did not return a unique result: 2 results were returned
48.9.3. Executing an update/delete query
48.9.4. could not initialize proxy [cn.netkiller.domain.Device#16] - no Session
48.9.5. this is incompatible with sql_mode=only_full_group_by
48.9.6. A TupleBackedMap cannot be modified
49. Spring Data with Redis
49.1. 集成 Redis XML 方式
49.1.1. pom.xml
49.1.2. springframework-servlet.xml
49.1.3. Controller
49.1.4. index.jsp
49.1.5. 测试
49.2. 通过构造方法实例化 Redis
49.3. stringRedisTemplate 基本用法
49.4. RedisTemplate
49.4.1. 设置缓存时间
49.4.2. increment
49.4.3. 删除 key
49.4.4. 对象存储
49.4.5. 获取过期时间
49.4.6. 过期时间未执行
49.5. ValueOperations
49.5.1. 字符串截取
49.5.2. 追加字符串
49.5.3. 设置键的字符串值并返回其旧值
49.5.4. 返回字符串长度
49.5.5. 如果key不存便缓存。
49.5.6. 缓存多个值 /获取多个值 multiSet / multiGet
49.5.7. setBit / getBit 二进制位操作
49.6. 列表操作
49.6.1. rightPush
49.6.2. rightPushAll
49.6.3. rightPushIfPresent
49.6.4. leftPush
49.6.5. leftPushAll
49.6.6. range
49.7. SetOperations 数据类型
49.7.1. 返回集合中的所有成员
49.7.2. 取出一个成员
49.7.3. 随机获取无序集合中的一个元素
49.7.4. 随机获取 n 个成员(存在重复数据)
49.7.5. 随机获取 n 个不重复成员
49.7.6. 在两个 SET 间移动数据
49.7.7. 成员删除
49.7.8. 返回集合数量
49.7.9. 判断元素是否在集合成员中
49.7.10. 对比两个集合求交集
49.7.11. 对比两个集合求交集,然后存储到新的 key 中
49.7.12. 合并两个集合,并去处重复数据
49.7.13. 合并两个集合去重复后保存到新的 key 中
49.7.14. 计算两个合集的差集
49.7.15. 计算两个合集的差集,然后保存到新的 key 中
49.7.16. 遍历 SET 集合
49.8. ZSetOperations 有序的 set 集合
49.9. HashOperations
49.9.1. put
49.9.2. putAll
49.9.3. 从键中的哈希获取给定hashKey的值
49.9.4. delete
49.9.5. 确定哈希hashKey是否存在
49.9.6. 从哈希中获取指定的多个 hashKey 的值
49.9.7. 只有hashKey不存在时才能添加值
49.9.8. 获取整个Hash
49.9.9. 获取所有key
49.9.10. 通过 hashKey 获取所有值
49.9.11. 值加法操作
49.9.12. 遍历 Hash 表
49.10. 存储 Json 对象
49.10.1. 集成 RedisTemplate 定义新类 JsonRedisTemplate
49.10.2. 配置 Redis
49.10.3. 测试
49.11. Spring Data Redis - Repository Examples
49.11.1. @EnableRedisRepositories 启动 Redis 仓库
49.11.2. 定义 Domain 类
49.11.3. Repository 接口
49.11.4. 测试代码
49.12. CacheService
49.13. FAQ
49.13.1. Spring Data Redis
50. Spring Data with MongoDB
50.1. Example Spring Data MongoDB
50.1.1. pom.xml
50.1.2. springframework-servlet.xml
50.1.3. POJO
50.1.4. Controller
50.1.5. 查看测试结果
50.1.6. 条件查询
50.2. MongoDB 多数据源
50.2.1. Maven
50.2.2. Application 禁止自动配置 MongoDB
50.2.3. application.properties 新增配置项
50.2.4. MongoDB 配置类
50.2.5. 创建 Document 关系映射类
50.2.6. 测试控制器
50.2.7. 测试
50.3. @Document
50.3.1. 指定表名
50.3.2. @Id
50.3.3. @Version
50.3.4. @Field 定义字段名
50.3.5. @Indexed
50.3.6. @CompoundIndex 复合索引
50.3.7. @TextIndexed
50.3.8. @GeoSpatialIndex 地理位置索引
50.3.9. @Transient 丢弃数据,不存到 mongodb
50.3.10. @DBRef 做外外键引用
50.3.11. @DateTimeFormat
50.3.12. @NumberFormat
50.3.13. 在 @Document 中使用 Enum 类型
50.3.14. 在 @Document 中定义数据结构 List/Map
50.3.15. GeoJson 数据类型
50.4. MongoRepository
50.4.1. 扫描仓库接口
50.4.2. findAll()
50.4.3. deleteAll()
50.4.4. save()
50.4.5. count()
50.4.6. exists() 判断是否存在
50.4.7. existsById()
50.4.8. findByXXXX
50.4.9. findAll with OrderBy
50.4.10. findAll with Sort
50.4.11. FindAll with Pageable
50.4.12. StartingWith 和 EndingWith
50.4.13. Between
50.4.14. Before / After
50.4.15. @Query
50.5. mongoTemplate
50.5.1. Save 保存
50.5.2. Insert
50.5.3. updateFirst 修改符合条件第一条记录
50.5.4. updateMulti 修改符合条件的所有
50.5.5. 查找并保存
50.5.6. upsert - 修改符合条件时如果不存在则添加
50.5.7. 删除
50.5.8. 查找一条数据
50.5.9. 查找所有数据
50.5.10. Query
50.5.11. Criteria
50.5.12. Update
50.5.13. BasicUpdate
50.5.14. Sort
50.5.15. Query + PageRequest
50.5.16. newAggregation
50.5.17. 创建索引
50.5.18. 子对象操作
50.6. GeoJson 反序列化
50.7. FAQ
50.7.1. location object expected, location array not in correct format; nested exception is com.mongodb.MongoWriteException: location object expected, location array not in correct format
51. Spring Data with Elasticsearch
51.1. 内嵌 Elasticsearch
51.1.1. Maven
51.1.2. src/main/resources/application.properties
51.1.3. Domain Class
51.1.4. ElasticsearchRepository
51.1.5. SearchRestController
51.1.6. 测试
51.2. 集群模式
51.3. Document
51.4. Elasticsearch 删除操作
51.5. FAQ
51.5.1. java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]
52. Spring boot with Data restful
52.1. Maven
53. Apache ShardingSphere
53.1. 微服务集群环境,雪花算法出现重复ID
53.1.1. 方案一、配置实现
53.1.2. 方案二、代码实现
IV. Spring Security
54. Springboot 3 + Security 6
54.1. Spring Security with HTTP Auth
54.1.1. 默认配置
54.1.2. 设置用户名和密码
54.1.3. 禁用 Security
54.1.4. 设置角色
54.2. Springboot 3 Security + OncePerRequestFilter
54.2.1. OncePerRequestFilter
54.2.2. SecurityConfiguration
54.3. SecurityFilterChain
54.4. @PreAuthorize
54.4.1. hasRole
54.4.2. hasAnyRole
54.4.3. 从 HttpServletRequest 返回的 request 变量中判断角色
54.4.4. getAuthentication() 获得角色
54.4.5. UserDetailsService
54.5. httpBasic 配置
54.6. InvalidClaimException: The Token can't be used before
55. Spring Authorization Server
55.1. Oauth2 协议
55.1.1. token
55.1.2. grant_type
55.1.3. 授权码授权模式(Authorization Code Grant)
55.1.4. 密码模式(Resource Owner Password Credentials Grant)
55.1.5. 客户端凭证模式(Client Credentials Grant)
55.1.6. 刷新 TOKEN 方式
55.2. Maven 依赖
55.3. Spring cloud with Oauth2
55.3.1. authorization_code
55.3.2. Spring boot with Oauth2 - Password
55.3.3. Spring boot with Oauth2 jwt
55.3.4. Spring boot with Oauth2 jwt 非对称证书
55.3.5. Apple iOS 访问 Oauth2
55.3.6. Oauth2 客户端
55.3.7. Android Oauth2 + Jwt example
55.3.8. RestTemplate 使用 HttpClient
55.3.9. 自签名证书信任问题
55.3.10. Principal
55.3.11. SecurityContextHolder 对象
55.3.12. 资源服务器配置
55.3.13. Client
55.3.14. Oauth2 常见问题
56. Spring boot with Spring security(2.x)
56.1. Spring security 静态配置例子
56.1.1. Maven
56.1.2. Reource
56.1.3. Application
56.1.4. WebSecurityConfigurer
56.1.5. RestController
56.1.6. 测试
56.2. Spring + Security + MongoDB
56.2.1. Account
56.2.2. AccountRepository
56.2.3. WebSecurityConfiguration
56.3. Spring Boot with Web Security(2.x)
56.3.1. EnableWebSecurity
56.3.2. Web静态资源
56.3.3. 正则匹配
56.3.4. 登陆页面,失败页面,登陆中页面
56.3.5. CORS
56.3.6. X-Frame-Options 安全
56.4. 访问控制列表(Access Control List,ACL)
56.4.1. antMatchers
56.4.2. HTTP Auth
56.4.3. Rest
56.4.4. hasRole
56.4.5. hasAnyRole()
56.4.6. withUser
V. Spring Cloud
57. Spring Cloud
57.1. Spring Cloud 相关的 application.properties 配置
57.1.1. 启用或禁用 bootstrap
57.1.2. bootstrap.properties 配置文件
58. Spring Cloud Config
58.1. Maven 项目 pom.xml 文件
58.2. Server
58.2.1. Maven config 模块
58.2.2. Application
58.2.3. application.properties
58.2.4. Git 仓库
58.2.5. 测试服务器
58.3. Client
58.3.1. Maven pom.xml
58.3.2. Application
58.3.3. bootstrap.properties
58.3.4. 测试 client
58.4. Config 高级配置
58.4.1. 仓库配置
58.4.2. Config server 用户认证
58.4.3. 加密敏感数据
58.4.4. Spring Cloud Config JDBC Backend
58.5. Old
58.5.1. Server (Camden.SR5)
58.5.2. Client (Camden.SR5)
59. Spring Cloud Consol
59.1. Spring Cloud Consul 配置
59.2. Maven 父项目
59.3. Consul 服务生产者
59.3.1. Maven
59.3.2. application.properties
59.3.3. SpringApplication
59.3.4. TestController
59.4. Consul 服务消费者
59.4.1. Maven
59.4.2. application.properties
59.4.3. SpringApplication
59.4.4. TestController
59.5. Openfeign
59.5.1. Maven
59.5.2. application.properties
59.5.3. SpringApplication
59.5.4. Feign 接口
59.5.5. TestController
60. Spring Cloud Netflix
60.1. Eureka Server
60.1.1. Maven
60.1.2. Application
60.1.3. application.properties
60.1.4. 检查注册服务器
60.2. Eureka Client
60.2.1. Maven
60.2.2. Application
60.2.3. RestController
60.2.4. application.properties
60.2.5. 测试
60.3. Feign client
60.3.1. Maven
60.3.2. Application
60.3.3. interface
60.3.4. application.properties
60.3.5. 测试
60.3.6. fallback
60.4. 为 Eureka Server 增加用户认证
60.4.1. Maven
60.4.2. application.properties
60.4.3. Eureka Client
60.4.4. Feign Client
60.5. Eureka 配置项
60.5.1. /eureka/apps
60.5.2. Eureka instance 配置项
60.5.3. Eureka client 配置项
60.5.4. Eureka Server配置项
60.6. ribbon
60.6.1.
60.6.2. LoadBalancerClient 实例
60.6.3. Ribbon 相关配置
60.7. 获取 EurekaClient 信息
60.8. Zuul
60.8.1. Maven
60.8.2. EnableZuulProxy
60.8.3. application.yml
60.8.4. 负载均衡配置
61. Openfeign
61.1. Openfeign 扫描包配置
61.2. 用户认证
61.3. 应用实例
61.4. 配置连接方式
61.4.1. httpclient
61.4.2. okhttp
61.5. 配置手册
62. Spring Cloud Gateway
62.1. Gateway 例子
62.1.1. Maven
62.1.2. SpringApplication
62.1.3. application.yml
62.1.4. RouteLocator 方式
62.2. 路由配置
62.2.1. 转发操作
62.2.2. URL 参数
63. Spring Cloud Sleuth
63.1. logback 安装
64. Spring Cloud with Kubernetes
64.1. Config
64.1.1. Maven 依赖
64.1.2. Spring Cloud 配置文件
64.1.3. 程序文件
64.1.4. Kubernetes 编排脚本
64.1.5. 测试
64.2. 注册发现
64.2.1. Maven 父项目
64.2.2. provider
64.2.3. consumer
64.2.4. 测试
64.2.5.
65. Spring Cloud Alibaba
65.1. 安装 Nacos
65.1.1. Docker 安装 Nacos
65.1.2. Kubernetes 安装 Nacos
65.1.3. IP限制,白名单
65.1.4. 防火墙配置
65.2. Kubernetes 部署微服务
65.2.1. pom.xml 中加入 docker 插件
65.2.2. 容器启动脚本
65.2.3. 构建 docker 镜像
65.2.4. 编排 kubernetes 容器
65.2.5. 启动指定 nacos
65.3. Nacos 配置中心/注册中心代码实例
65.3.1. Maven
65.3.2. SpringBootApplication
65.3.3. ConfigController
65.3.4. 配置文件
65.4. FAQ
65.4.1. 禁用 Nacos
65.4.2. 禁止注册
65.4.3. Failed to bind properties under 'server.tomcat.basedir' to java.io.File:
65.4.4. 不读取 bootstrap.yaml 文件
65.4.5. WARN [com.alibaba.nacos.client.naming:177] [,] - out of date data received, old-t: 1665711914993, new-t: 1665711902390
65.4.6. User limit of inotify instances reached or too many open files
65.4.7. 开启权限
65.4.8. ERROR Whitelabel
65.4.9.
66. FAQ
66.1. Cannot execute request on any known server
66.2. @EnableDiscoveryClient与@EnableEurekaClient 区别
66.3. Feign请求超时
66.4. 已停止的微服务节点注销慢或不注销
66.5. Feign 启动出错 PathVariable annotation was empty on param 0.
66.6. Feign 提示 Consider defining a bean of type 'common.feign.Cms' in your configuration.
66.7. Load balancer does not have available server for client
66.8. Eureka Client (Dalston.SR1)
66.8.1. Maven
66.8.2. Application
66.8.3. RestController
66.8.4. application.properties
66.8.5. 测试
66.9. Config Server(1.3.1.RELEASE)
66.9.1. Server
66.9.2. Client
66.10. feign.RetryableException: Read timed out executing
67. Spring Integration
67.1. Spring Redis Lock
67.1.1. Maven 依赖
67.1.2. 配置锁
67.1.3. 使用方法
67.2. MQTT Support
67.2.1. 入站消息通道适配器
67.2.2. 出站通道适配器
67.2.3. @MessagingGateway 定义消息网管接口
67.2.4. 手动 ACK 应答
67.2.5. Spring boot with Mqtt v5
1. 附录
1.1. Springboot example

范例清单

12.1. Example Spring boot with Oracle
2. RedisTemplate
20.1. Spring boot with Apache kafka.
20.2. Spring boot with Apache kafka.
20.3. Test Spring Kafka
35.1. Spring boot with Email (pom.xml)
41.1. Spring boot with Velocity template (pom.xml)
45.1. MyBatis
49.1. Spring Data Redis Example
50.1. Spring Data MongoDB - springframework-servlet.xml
66.1. Share feign interface.