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-02-29 18:08:04

版权声明

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

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.5. 命令行注入配置项
5.5.1. spring.profiles.active 参数切换配置文件
5.5.2. SpringApplicationBuilder.properties() 方法添加配置项
5.5.3. 禁用命令行注入环境变量
5.6.
5.7. PropertyResolver 获取配置
5.8. 参数引用
5.9. 默认值
5.10. 产生随机数
5.10.1. 随机数
5.11. 多行字符串
5.12. 注入多值属性 arrays, list, set
5.13. List 列表类型
5.14. Map类型
5.15. Binder
5.16. 加密 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. 启用 Cache
34.3. @Cacheable 的用法
34.3.1. SpEL表达式
34.3.2. 排除 null 结果
34.3.3. 排除 empty
34.4. @CachePut 用法
34.5. 清空缓存
34.6. @Caching
34.7. 解决Expire 和 TTL 过期时间
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.2.17. StreamingResponseBody 输出 Raw Data
41.3. @RestController
41.3.1. 上传文件
41.3.2. 返回实体
41.3.3. JSON
41.3.4. 处理原始 RAW JSON 数据
41.3.5. 返回 JSON 对象 NULL 专为 "" 字符串
41.3.6. XML
41.3.7. 兼容传统 json 接口
41.3.8. 上传文件
41.3.9. Spring boot with csv
41.3.10. Json 处理
41.3.11. synchronized
41.3.12. SSE Streaming in Spring MVC
41.3.13. StreamingResponseBody
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. 校验器(Validator)
41.5.1. 常规用法
41.5.2. 自定义注解
41.6. Interceptor/Filter 拦截器/过滤
41.6.1. Session 拦截
41.6.2. Token 拦截
41.6.3. 过滤器
41.6.4. 拦截器获取PathVariable变量
41.7. String boot with RestTemplate
41.7.1. RestTemplate Example
41.7.2. GET 操作
41.7.3. POST 操作
41.7.4. PUT 操作
41.7.5. Delete 操作
41.7.6. 上传文件
41.7.7. HTTP Auth
41.7.8. PKCS12
41.7.9. Timeout 超时设置
41.8. RestClient
41.8.1. 创建 RestClient
41.8.2. Get 操作
41.8.3. Post Json
41.8.4. HTTP Authorization Basic
41.8.5. onStatus
41.8.6. 下载二进制流
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.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. Spring boot with Webpage
45.1. Maven
45.2. application.properties
45.3. Application
45.4. IndexController
45.5. src/main/webapp/WEB-INF/jsp/index.jsp
45.6. 集成模板引擎
46. Spring boot with Velocity template
46.1. Maven
46.2. Resource
46.3. Application
46.4. RestController
46.5. Test
47. Spring boot with Thymeleaf
47.1. Maven
47.2. application.properties
47.3. Controller
47.4. HTML5 Template
48. Tomcat Spring 运行环境
48.1. Maven
48.2. Spring MVC configuration
48.3. Tomcat
48.4. 集成 Mybatis
48.4.1. pom.xml
48.4.2. properties
48.4.3. dataSource
48.4.4. SqlSessionFactory
48.4.5. Mapper 扫描
48.4.6. Mapper 单一class映射
48.4.7. Service
48.4.8. 测试实例
III. Spring Data
49. EntityManager
50. Spring Data with JdbcTemplate
50.1. execute
50.2. queryForInt
50.3. queryForLong
50.4. queryForObject
50.4.1. 返回整形与字符型
50.4.2. 查询 Double 类型数据库
50.4.3. 返回日期
50.4.4. 返回结果集
50.4.5. 通过 "?" 向SQL传递参数
50.4.6. RowMapper 记录映射
50.5. queryForList
50.5.1. Iterator 用法
50.5.2. for 循环
50.5.3. forEach 用法
50.6. queryForMap
50.7. query
50.7.1. ResultSet
50.7.2. ResultSetExtractor
50.7.3. RowMapper
50.8. queryForRowSet
50.9. update
50.10. MapSqlParameterSource
50.11. 实例参考
50.11.1. 参数传递技巧
51. Spring Data with MySQL
51.1. 选择数据库表引擎
51.2. 声明实体
51.2.1. @Entity 声明实体
51.2.2. @Table 定义表名
51.2.3. @Id 定义主键
51.2.4. @Column 定义字段:
51.2.5. 非数据库字段
51.2.6. @Lob 注解属性将被持久化为 Blog 或 Clob 类型
51.2.7. @NotNull 不能为空声明
51.2.8. @Temporal 日期定义
51.2.9. 创建日期
51.2.10. @DateTimeFormat 处理日期时间格式
51.2.11. Enum 枚举数据类型
51.2.12. SET 数据结构
51.2.13. JSON 数据类型
51.2.14. 索引
51.2.15. 嵌入
51.2.16. 外键
51.2.17. 映射集合属性
51.2.18. @JsonIgnore
51.2.19. @EnableJpaAuditing 开启 JPA 审计功能
51.2.20. 注释 @Comment
51.2.21. @Pattern 数据匹配
51.2.22. 实体继承
51.3. Repository
51.3.1. CrudRepository
51.3.2. JpaRepository
51.3.3. PagingAndSortingRepository
51.3.4. findByXXX
51.3.5. count 操作
51.3.6. delete 删除操作
51.3.7. OrderBy
51.3.8. GreaterThan
51.3.9. Sort 排序操作操作
51.3.10. Pageable 翻页操作
51.3.11. @DynamicInsert 与 @DynamicUpdate
51.3.12. 继承已存在的 Repository
51.3.13. 自定义返回字段
51.4. TransactionTemplate
51.5. JPQL @Query
51.5.1. @Modifying 更新/删除
51.5.2. 事务 @Transactional
51.5.3. 参数传递
51.5.4. 原生 SQL 操作
51.5.5. @Query 与 Pageagble
51.5.6. 返回指定字段
51.5.7. 返回指定的模型
51.5.8. Collection
51.5.9. Sort
51.5.10. 锁 @Lock
52. Spring Data with Redis
52.1. 集成 Redis XML 方式
52.1.1. pom.xml
52.1.2. springframework-servlet.xml
52.1.3. Controller
52.1.4. index.jsp
52.1.5. 测试
52.2. 通过构造方法实例化 Redis
52.3. RedisTemplate
52.3.1. 设置缓存时间
52.3.2. increment
52.3.3. 删除 key
52.3.4. 对象存储
52.3.5. 获取过期时间
52.3.6. 过期时间未执行
52.4. stringRedisTemplate 基本用法
52.5. ValueOperations
52.5.1. 字符串截取
52.5.2. 追加字符串
52.5.3. 设置键的字符串值并返回其旧值
52.5.4. 返回字符串长度
52.5.5. 如果key不存便缓存。
52.5.6. 缓存多个值 /获取多个值 multiSet / multiGet
52.5.7. setBit / getBit 二进制位操作
52.6. 列表操作
52.6.1. rightPush
52.6.2. rightPushAll
52.6.3. rightPushIfPresent
52.6.4. leftPush
52.6.5. leftPushAll
52.6.6. range
52.7. SetOperations 数据类型
52.7.1. 返回集合中的所有成员
52.7.2. 取出一个成员
52.7.3. 随机获取无序集合中的一个元素
52.7.4. 随机获取 n 个成员(存在重复数据)
52.7.5. 随机获取 n 个不重复成员
52.7.6. 在两个 SET 间移动数据
52.7.7. 成员删除
52.7.8. 返回集合数量
52.7.9. 判断元素是否在集合成员中
52.7.10. 对比两个集合求交集
52.7.11. 对比两个集合求交集,然后存储到新的 key 中
52.7.12. 合并两个集合,并去处重复数据
52.7.13. 合并两个集合去重复后保存到新的 key 中
52.7.14. 计算两个合集的差集
52.7.15. 计算两个合集的差集,然后保存到新的 key 中
52.7.16. 遍历 SET 集合
52.8. ZSetOperations 有序的 set 集合
52.9. HashOperations
52.9.1. put
52.9.2. putAll
52.9.3. 从键中的哈希获取给定hashKey的值
52.9.4. delete
52.9.5. 确定哈希hashKey是否存在
52.9.6. 从哈希中获取指定的多个 hashKey 的值
52.9.7. 只有hashKey不存在时才能添加值
52.9.8. 获取整个Hash
52.9.9. 获取所有key
52.9.10. 通过 hashKey 获取所有值
52.9.11. 值加法操作
52.9.12. 遍历 Hash 表
52.10. 存储 Json 对象
52.10.1. 集成 RedisTemplate 定义新类 JsonRedisTemplate
52.10.2. 配置 Redis
52.10.3. 测试
52.11. Spring Data Redis - Repository Examples
52.11.1. @EnableRedisRepositories 启动 Redis 仓库
52.11.2. 定义 Domain 类
52.11.3. Repository 接口
52.11.4. 测试代码
53. Spring Data with MongoDB
53.1. Example Spring Data MongoDB
53.1.1. pom.xml
53.1.2. springframework-servlet.xml
53.1.3. POJO
53.1.4. Controller
53.1.5. 查看测试结果
53.1.6. 条件查询
53.2. MongoDB 多数据源
53.2.1. Maven
53.2.2. Application 禁止自动配置 MongoDB
53.2.3. application.properties 新增配置项
53.2.4. MongoDB 配置类
53.2.5. 创建 Document 关系映射类
53.2.6. 测试控制器
53.2.7. 测试
53.3. @Document
53.3.1. 指定表名
53.3.2. @Id
53.3.3. @Version
53.3.4. @Field 定义字段名
53.3.5. @Indexed
53.3.6. @CompoundIndex 复合索引
53.3.7. @TextIndexed
53.3.8. @GeoSpatialIndex 地理位置索引
53.3.9. @Transient 丢弃数据,不存到 mongodb
53.3.10. @DBRef 做外外键引用
53.3.11. @DateTimeFormat
53.3.12. @NumberFormat
53.3.13. 在 @Document 中使用 Enum 类型
53.3.14. 在 @Document 中定义数据结构 List/Map
53.3.15. GeoJson 数据类型
53.4. MongoRepository
53.4.1. 扫描仓库接口
53.4.2. findAll()
53.4.3. deleteAll()
53.4.4. save()
53.4.5. count()
53.4.6. exists() 判断是否存在
53.4.7. existsById()
53.4.8. findByXXXX
53.4.9. findAll with OrderBy
53.4.10. findAll with Sort
53.4.11. FindAll with Pageable
53.4.12. StartingWith 和 EndingWith
53.4.13. Between
53.4.14. Before / After
53.4.15. @Query
53.5. mongoTemplate
53.5.1. Save 保存
53.5.2. Insert
53.5.3. updateFirst 修改符合条件第一条记录
53.5.4. updateMulti 修改符合条件的所有
53.5.5. 查找并保存
53.5.6. upsert - 修改符合条件时如果不存在则添加
53.5.7. 删除
53.5.8. 查找一条数据
53.5.9. 查找所有数据
53.5.10. Query
53.5.11. Criteria
53.5.12. Update
53.5.13. BasicUpdate
53.5.14. Sort
53.5.15. Query + PageRequest
53.5.16. newAggregation
53.5.17. 创建索引
53.5.18. 子对象操作
53.6. GeoJson 反序列化
53.7. FAQ
53.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
54. Spring Data with Elasticsearch
54.1. 内嵌 Elasticsearch
54.1.1. Maven
54.1.2. src/main/resources/application.properties
54.1.3. Domain Class
54.1.4. ElasticsearchRepository
54.1.5. SearchRestController
54.1.6. 测试
54.2. 集群模式
54.3. Document
54.4. Elasticsearch 删除操作
54.5. FAQ
54.5.1. java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]
55. Spring boot with Data restful
55.1. Maven
56. Apache ShardingSphere
56.1. 微服务集群环境,雪花算法出现重复ID
56.1.1. 方案一、配置实现
56.1.2. 方案二、代码实现
IV. Spring Security
57. Springboot 3 + Security 6
57.1. Spring Security with HTTP Auth
57.1.1. 默认配置
57.1.2. 设置用户名和密码
57.1.3. 禁用 Security
57.1.4. 设置角色
57.2. Springboot 3 Security + OncePerRequestFilter
57.2.1. OncePerRequestFilter
57.2.2. SecurityConfiguration
57.3. SecurityFilterChain
57.4. @PreAuthorize
57.4.1. hasRole
57.4.2. hasAnyRole
57.4.3. 从 HttpServletRequest 返回的 request 变量中判断角色
57.4.4. getAuthentication() 获得角色
57.4.5. UserDetailsService
57.5. httpBasic 配置
57.6.
58. Spring Authorization Server
58.1. Oauth2 协议
58.1.1. token
58.1.2. grant_type
58.1.3. 授权码授权模式(Authorization Code Grant)
58.1.4. 密码模式(Resource Owner Password Credentials Grant)
58.1.5. 客户端凭证模式(Client Credentials Grant)
58.1.6. 刷新 TOKEN 方式
58.2. Maven 依赖
58.3. Spring cloud with Oauth2
58.3.1. authorization_code
58.3.2. Spring boot with Oauth2 - Password
58.3.3. Spring boot with Oauth2 jwt
58.3.4. Spring boot with Oauth2 jwt 非对称证书
58.3.5. Apple iOS 访问 Oauth2
58.3.6. Oauth2 客户端
58.3.7. Android Oauth2 + Jwt example
58.3.8. RestTemplate 使用 HttpClient
58.3.9. 自签名证书信任问题
58.3.10. Principal
58.3.11. SecurityContextHolder 对象
58.3.12. 资源服务器配置
58.3.13. Client
58.3.14. Oauth2 常见问题
59. Spring boot with Spring security(2.x)
59.1. Spring security 静态配置例子
59.1.1. Maven
59.1.2. Reource
59.1.3. Application
59.1.4. WebSecurityConfigurer
59.1.5. RestController
59.1.6. 测试
59.2. Spring + Security + MongoDB
59.2.1. Account
59.2.2. AccountRepository
59.2.3. WebSecurityConfiguration
59.3. Spring Boot with Web Security(2.x)
59.3.1. EnableWebSecurity
59.3.2. Web静态资源
59.3.3. 正则匹配
59.3.4. 登陆页面,失败页面,登陆中页面
59.3.5. CORS
59.3.6. X-Frame-Options 安全
59.4. 访问控制列表(Access Control List,ACL)
59.4.1. antMatchers
59.4.2. HTTP Auth
59.4.3. Rest
59.4.4. hasRole
59.4.5. hasAnyRole()
59.4.6. withUser
V. Spring Cloud
60. Spring Cloud
60.1. Spring Cloud 相关的 application.properties 配置
60.1.1. 启用或禁用 bootstrap
60.1.2. bootstrap.properties 配置文件
61. Spring Cloud Config
61.1. Maven 项目 pom.xml 文件
61.2. Server
61.2.1. Maven config 模块
61.2.2. Application
61.2.3. application.properties
61.2.4. Git 仓库
61.2.5. 测试服务器
61.3. Client
61.3.1. Maven pom.xml
61.3.2. Application
61.3.3. bootstrap.properties
61.3.4. 测试 client
61.4. Config 高级配置
61.4.1. 仓库配置
61.4.2. Config server 用户认证
61.4.3. 加密敏感数据
61.4.4. Spring Cloud Config JDBC Backend
61.5. Old
61.5.1. Server (Camden.SR5)
61.5.2. Client (Camden.SR5)
62. Spring Cloud Consol
62.1. Spring Cloud Consul 配置
62.2. Maven 父项目
62.3. Consul 服务生产者
62.3.1. Maven
62.3.2. application.properties
62.3.3. SpringApplication
62.3.4. TestController
62.4. Consul 服务消费者
62.4.1. Maven
62.4.2. application.properties
62.4.3. SpringApplication
62.4.4. TestController
62.5. Openfeign
62.5.1. Maven
62.5.2. application.properties
62.5.3. SpringApplication
62.5.4. Feign 接口
62.5.5. TestController
63. Spring Cloud Netflix
63.1. Eureka Server
63.1.1. Maven
63.1.2. Application
63.1.3. application.properties
63.1.4. 检查注册服务器
63.2. Eureka Client
63.2.1. Maven
63.2.2. Application
63.2.3. RestController
63.2.4. application.properties
63.2.5. 测试
63.3. Feign client
63.3.1. Maven
63.3.2. Application
63.3.3. interface
63.3.4. application.properties
63.3.5. 测试
63.3.6. fallback
63.4. 为 Eureka Server 增加用户认证
63.4.1. Maven
63.4.2. application.properties
63.4.3. Eureka Client
63.4.4. Feign Client
63.5. Eureka 配置项
63.5.1. /eureka/apps
63.5.2. Eureka instance 配置项
63.5.3. Eureka client 配置项
63.5.4. Eureka Server配置项
63.6. ribbon
63.6.1.
63.6.2. LoadBalancerClient 实例
63.6.3. Ribbon 相关配置
63.7. 获取 EurekaClient 信息
63.8. Zuul
63.8.1. Maven
63.8.2. EnableZuulProxy
63.8.3. application.yml
63.8.4. 负载均衡配置
64. Openfeign
64.1. Openfeign 扫描包配置
64.2. 用户认证
64.3. 应用实例
64.4. 配置连接方式
64.4.1. httpclient
64.4.2. okhttp
64.5. 配置手册
65. Spring Cloud Gateway
65.1. Gateway 例子
65.1.1. Maven
65.1.2. SpringApplication
65.1.3. application.yml
65.1.4. RouteLocator 方式
65.2. 路由配置
65.2.1. 转发操作
65.2.2. URL 参数
66. Spring Cloud Sleuth
66.1. logback 安装
67. Spring Cloud with Kubernetes
67.1. Config
67.1.1. Maven 依赖
67.1.2. Spring Cloud 配置文件
67.1.3. 程序文件
67.1.4. Kubernetes 编排脚本
67.1.5. 测试
67.2. 注册发现
67.2.1. Maven 父项目
67.2.2. provider
67.2.3. consumer
67.2.4. 测试
67.2.5.
68. Spring Cloud Alibaba
68.1. 安装 Nacos
68.1.1. Docker 安装 Nacos
68.1.2. Kubernetes 安装 Nacos
68.1.3. IP限制,白名单
68.1.4. 防火墙配置
68.2. Kubernetes 部署微服务
68.2.1. pom.xml 中加入 docker 插件
68.2.2. 容器启动脚本
68.2.3. 构建 docker 镜像
68.2.4. 编排 kubernetes 容器
68.2.5. 启动指定 nacos
68.3. Nacos 配置中心/注册中心代码实例
68.3.1. Maven
68.3.2. SpringBootApplication
68.3.3. ConfigController
68.3.4. 配置文件
68.4. FAQ
68.4.1. 禁用 Nacos
68.4.2. 禁止注册
68.4.3. Failed to bind properties under 'server.tomcat.basedir' to java.io.File:
68.4.4. 不读取 bootstrap.yaml 文件
68.4.5. WARN [com.alibaba.nacos.client.naming:177] [,] - out of date data received, old-t: 1665711914993, new-t: 1665711902390
68.4.6. User limit of inotify instances reached or too many open files
68.4.7. 开启权限
68.4.8. ERROR Whitelabel
68.4.9.
69. FAQ
69.1. Cannot execute request on any known server
69.2. @EnableDiscoveryClient与@EnableEurekaClient 区别
69.3. Feign请求超时
69.4. 已停止的微服务节点注销慢或不注销
69.5. Feign 启动出错 PathVariable annotation was empty on param 0.
69.6. Feign 提示 Consider defining a bean of type 'common.feign.Cms' in your configuration.
69.7. Load balancer does not have available server for client
69.8. Eureka Client (Dalston.SR1)
69.8.1. Maven
69.8.2. Application
69.8.3. RestController
69.8.4. application.properties
69.8.5. 测试
69.9. Config Server(1.3.1.RELEASE)
69.9.1. Server
69.9.2. Client
69.10. feign.RetryableException: Read timed out executing
70. Spring Integration
70.1. Spring Redis Lock
70.1.1. Maven 依赖
70.1.2. 配置锁
70.1.3. 使用方法
70.2. MQTT Support
70.2.1. 入站消息通道适配器
70.2.2. 出站通道适配器
70.2.3. @MessagingGateway 定义消息网管接口
70.2.4. 手动 ACK 应答
70.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)
46.1. Spring boot with Velocity template (pom.xml)
48.1. MyBatis
52.1. Spring Data Redis Example
53.1. Spring Data MongoDB - springframework-servlet.xml
69.1. Share feign interface.