Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

Netkiller Spring Cloud 手札(2023版)

Spring Cloud Cookbook

Mr. Neo Chan, 陈景峯(BG7NYT)



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


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

电子书最近一次更新于 2023-01-16 08:35:22

版权声明

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

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. 联系方式
1. Spring 开发环境
1.1. Java 开发环境
1.2. 安装 Spring Tool Suite
1.3. Dashboard
1.4. Spring Initializr - Bootstrap your application
2. Spring Boot
2.1. Spring Boot Quick start
2.1.1. 创建项目
2.1.2. pom.xml
2.1.3. Controller
2.2. Springboot with Maven
2.2.1. resource
2.2.2. Maven run
2.2.3. Spring Boot maven 插件 build-image
2.2.4. 生成项目信息
2.3. SpringApplication
2.3.1. 运行 Spring boot 项目
2.3.2. @SpringBootApplication
2.3.3. 获取 Resources 目录中的静态文件
2.3.4. @EnableAutoConfiguration
2.3.5. @ComponentScan
2.3.6. @EntityScan 实体扫描
2.3.7. @EnableJpaRepositories
2.3.8. CharacterEncodingFilter
2.3.9. 隐藏 Banner
2.3.10. 实体与仓库扫描
2.3.11. 列出 Beans
2.3.12. Tomcat 端口
2.3.13. 配置项设定
2.3.14. spring.profiles.active
2.4. 如何优雅停止 Springboot 运行
2.4.1. 准备工作
2.4.2. kill 命令演示
2.4.3. 容器中如何优雅关闭 Springboot
2.4.4. 写入PID文件
2.5. Properties 配置文件
2.5.1. application.properties 配置文件
2.5.2. Properties 文件
2.5.3. 加密 application.properties 中的敏感内容
2.6. Spring boot with Logging
2.6.1. 配置日志文件
2.6.2. 打印日志
2.6.3. logback 配置详解
2.6.4. 日志发送给 logstash
2.6.5. fluentd
2.6.6. Loki4j Logback
2.6.7. Log4j2 + Gelf + Logstash
2.6.8. 日志报警
2.6.9. Spring boot with ELK(Elasticsearch + Logstash + Kibana)
2.7. Undertow
2.7.1. Maven 依赖
2.7.2. Application
2.7.3. 相关配置
2.8. Spring boot with Jetty
2.9. Spring boot with HTTP2 SSL
2.9.1. 生成自签名证书
2.9.2. application.properties 配置文件
2.9.3. 启动 Spring boot
2.9.4. restTemplate 调用实例
2.9.5. HTTP2
2.10. Spring boot with Webpage
2.10.1. Maven
2.10.2. application.properties
2.10.3. Application
2.10.4. IndexController
2.10.5. src/main/webapp/WEB-INF/jsp/index.jsp
2.10.6. 集成模板引擎
2.11. Spring boot with Velocity template
2.11.1. Maven
2.11.2. Resource
2.11.3. Application
2.11.4. RestController
2.11.5. Test
2.12. Spring boot with Thymeleaf
2.12.1. Maven
2.12.2. application.properties
2.12.3. Controller
2.12.4. HTML5 Template
2.13. Spring boot with Redis
2.13.1. Spring boot with Redis
2.13.2. Redis Pub/Sub
2.14. Spring boot with MongoDB
2.14.1. Maven
2.14.2. Application
2.14.3. MongoTemplate
2.14.4. Repository
2.15. Spring boot with MySQL
2.15.1. Maven
2.15.2. Resource
2.15.3. Application
2.15.4. JdbcTemplate
2.15.5. CrudRepository
2.16. Spring boot with Oracle
2.16.1. Maven
2.16.2. application.properties
2.16.3. Application
2.16.4. CrudRepository
2.16.5. JdbcTemplate
2.16.6. Controller
2.17. Spring boot with PostgreSQL
2.17.1. pom.xml
2.17.2. application.properties
2.17.3. Application
2.17.4. CrudRepository
2.17.5. JdbcTemplate
2.17.6. Controller
2.17.7. Test
2.18. Spring boot with Elasticsearch
2.18.1. Maven
2.18.2. Application
2.18.3. application.properties
2.18.4. Domain
2.18.5. ElasticsearchRepository
2.19. Spring boot with Elasticsearch TransportClient
2.19.1. Maven
2.19.2. Application
2.19.3. application.properties
2.19.4. ElasticsearchConfiguration
2.19.5. RestController
2.20. Spring boot with Apache Hive
2.20.1. Maven
2.20.2. application.properties
2.20.3. Configuration
2.20.4. CURD 操作实例
2.21. Spring boot with Phoenix
2.21.1. Maven
2.21.2. application.properties
2.21.3. Configuration
2.22. Spring boot with Datasource
2.22.1. Master / Slave 主从数据库数据源配置
2.22.2. 多数据源配置
2.22.3. JPA 多数据源
2.23. 连接池配置
2.23.1. org.apache.tomcat.jdbc.pool.DataSource
2.23.2. druid
2.23.3. c3p0 - JDBC3 Connection and Statement Pooling
2.23.4. dbcp2
2.23.5. bonecp
2.23.6. HikariPool
2.24. Spring boot with RabbitMQ(AMQP)
2.24.1. maven
2.24.2. RabbitMQConfig
2.24.3. 生产者
2.24.4. 消费者
2.25. Spring boot with Apache Kafka
2.25.1. 安装 kafka
2.25.2. maven
2.25.3. Spring boot Application
2.25.4. EnableKafka
2.25.5. KafkaListener
2.25.6. 测试
2.25.7. 完整的发布订阅实例
2.25.8. Spring cloud with Kafka
2.26. Spring boot with Scheduling
2.26.1. Application.java
2.26.2. Component
2.26.3. 查看日志
2.26.4. 计划任务控制开关
2.26.5. @Scheduled 详解
2.26.6. Timer 例子
2.26.7. ScheduledExecutorService 例子
2.27. Spring boot with Swagger
2.27.1. Maven 文件
2.27.2. SpringApplication
2.27.3. EnableSwagger2
2.27.4. RestController
2.27.5. @Api()
2.27.6. @ApiOperation()
2.27.7. @ApiResponses
2.27.8. @ApiModel 实体类
2.28. Spring boot with lombok
2.28.1. @Builder
2.28.2. @Slf4j 注解
2.29. Spring boot with Docker
2.29.1. 通过 Docker 命令构建镜像
2.29.2. 通过 Maven 构建 Docker 镜像
2.29.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]
2.29.4. curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:8888
2.30. Spring boot with Docker stack
2.30.1. 编译 Docker 镜像
2.30.2.
2.31. Spring boot with Kubernetes
2.31.1. Kubernetes 编排脚本
2.31.2. 部署镜像
2.32. Spring boot with command line
2.32.1. Maven
2.32.2. CommandLineRunner 例子
2.32.3. ApplicationRunner 例子
2.33. Spring Boot Actuator
2.33.1. Maven 依赖
2.33.2. 与 Spring Boot Actuator 有关的配置
2.33.3. actuator 接口
2.33.4. 健康状态
2.33.5. 关机
2.33.6. info 配置信息
2.33.7. 计划任务
2.33.8. 修改 actuator 地址
2.33.9. metrics
2.34. String boot with RestTemplate
2.34.1. RestTemplate Example
2.34.2. GET 操作
2.34.3. POST 操作
2.34.4. PUT 操作
2.34.5. Delete 操作
2.34.6. 上传文件
2.34.7. HTTP Auth
2.34.8. PKCS12
2.34.9. Timeout 超时设置
2.35. SpringBootTest
2.35.1. Maven 依赖
2.35.2. 测试类
2.35.3.
2.35.4. JPA 测试
2.35.5. TestRestTemplate
2.35.6. Controller单元测试
2.35.7. WebTestClient
2.36. Spring boot with Aop
2.36.1. Aspect
2.37. Spring boot with starter
2.37.1. 实现 starter
2.37.2. 引用 starter
2.38. SpringBoot Admin
2.38.1. 依赖
2.38.2. 启用 Springboot Admin
2.38.3. Nginx 跨域
2.39. Spring boot with Grafana
2.39.1. Springboot 集成 InfluxDB
2.39.2. InfluxDB
2.40. Spring Boot with Prometheus
2.40.1. Maven 依赖
2.40.2. application.properties 配置文件
2.40.3. 启动类
2.40.4. 测试
2.40.5. 控制器监控
2.40.6. 自定义埋点监控
2.41. 设置默认时区
2.42. Spring boot with Git version
2.42.1. CommonRestController 公共控制器
2.42.2. VersionRestController 测试控制器
2.42.3. 创建 .gitattributes 文件
2.43. Spring boot with Session share
2.43.1. Redis
2.43.2. 测试 Session
2.43.3. JDBC
2.43.4. Springboot 2.1
2.44. Spring boot with Caching
2.44.1. maven
2.44.2. 启用 Cache
2.44.3. 测试 Controller
2.44.4. @Cacheable 的用法
2.44.5. @CachePut 用法
2.44.6. 解决Expire 和 TTL 过期时间
2.44.7. SpEL表达式
2.45. Spring boot with Email
2.45.1. Maven
2.45.2. Resource
2.45.3. POJO
2.45.4. RestController
2.45.5. Test
2.46. Spring boot with Hessian
2.46.1. Maven
2.46.2. Application
2.46.3. HessianServiceExporter
2.46.4. Service
2.46.5. RestController
2.47. Spring boot with Async
2.47.1. 最简单的配置
2.47.2. 异步线程池
2.48. Springboot with Ethereum (web3j)
2.48.1. Maven
2.48.2. application.properties
2.48.3. TestRestController
2.48.4. 测试
3. Spring MVC
3.1. @EnableWebMvc
3.1.1. CORS 跨域请求
3.1.2. Spring MVC CORS with WebMvcConfigurerAdapter
3.2. @Controller
3.2.1. @RequestMapping
3.2.2. @RequestBody
3.2.3. @RequestHeader - 获取 HTTP Header 信息
3.2.4. RequestMapping with Path Variables - @PathVariable
3.2.5. @ModelAttribute
3.2.6. @ResponseBody
3.2.7. @ResponseStatus 设置 HTTP 状态
3.2.8. @CrossOrigin
3.2.9. @CookieValue - 获取 Cookie 值
3.2.10. @SessionAttributes
3.2.11. ModelAndView
3.2.12. HttpServletRequest / HttpServletResponse
3.3. @RestController
3.3.1. 返回实体
3.3.2. JSON
3.3.3. 处理原始 RAW JSON 数据
3.3.4. 返回 JSON 对象 NULL 专为 "" 字符串
3.3.5. XML
3.3.6. 兼容传统 json 接口
3.3.7. @PageableDefault 分页
3.3.8. 上传文件
3.3.9. Spring boot with csv
3.3.10. Jackson
3.4. View
3.4.1. 配置静态文件目录
3.4.2. 添加静态文件目录
3.4.3. Using Spring’s form tag library
3.4.4. Thymeleaf
3.4.5. FreeMarker
3.5. Service
3.5.1. Application
3.5.2. 定义接口
3.5.3. 实现接口
3.5.4. 调用 Service
3.5.5. context.getBean 调用 Service
3.5.6. AopContext
3.6. i18n 国际化
3.6.1. 在 appliction.properties 中配置启用 i18n
3.6.2. 创建语言包文件
3.6.3. 控制器重引用语言包
3.6.4. 参数传递
3.7. 校验器(Validator)
3.7.1. 常规用法
3.7.2. 自定义注解
3.8. Interceptor
3.8.1. WebMvcConfigurerAdapter
3.8.2. HandlerInterceptor
3.9. FAQ
3.9.1. o.s.web.servlet.PageNotFound
3.9.2. HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
3.9.3. 同时使用 Thymeleaf 与 JSP
3.9.4. 排除静态内容
3.9.5. HTTP Status 406
3.9.6. Caused by: java.lang.IllegalArgumentException: Not a managed type: class common.domain.Article
3.9.7. {"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
4. WebFlux framework
4.1. Getting Started
4.1.1. Maven
4.1.2. Application
4.1.3. RestController
4.1.4. 测试
4.2. WebFlux Router
4.2.1. Component 原件
4.2.2. 路由配置
4.2.3. Thymeleaf
4.2.4. Webflux Redis
4.2.5. Webflux Mongdb
4.2.6. SSE
4.2.7. Mono/Flux
5. Spring Data
5.1. Spring Data with Redis
5.1.1. 集成 Redis XML 方式
5.1.2. RedisTemplate
5.1.3. Spring Data Redis - Repository Examples
5.2. Spring Data with MongoDB
5.2.1. Example Spring Data MongoDB
5.2.2. MongoDB 多数据源
5.2.3. @Document
5.2.4. MongoRepository
5.2.5. mongoTemplate
5.2.6. GeoJson 反序列化
5.2.7. FAQ
5.3. Spring Data with MySQL
5.3.1. 选择数据库表引擎
5.3.2. 声明实体
5.3.3. 实体继承
5.3.4. Repository
5.3.5. 事务 @Transactional
5.3.6. TransactionTemplate
5.3.7. 锁 @Lock
5.4. EntityManager
5.5. Spring Data with JdbcTemplate
5.5.1. execute
5.5.2. queryForInt
5.5.3. queryForLong
5.5.4. queryForObject
5.5.5. queryForList
5.5.6. queryForMap
5.5.7. query
5.5.8. queryForRowSet
5.5.9. update
5.5.10.
5.5.11. 实例参考
5.6. Spring boot with Data restful
5.6.1. Maven
5.7. Spring Data with Elasticsearch
5.7.1. 内嵌 Elasticsearch
5.7.2. 集群模式
5.7.3. Document
5.7.4. Elasticsearch 删除操作
5.7.5. FAQ
5.8. Spring Data FAQ
5.8.1. No identifier specified for entity
5.8.2. Oracle Date 类型显示日期和时间
5.8.3. java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
5.8.4. Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query
6. Spring Security
6.1. Spring Security with HTTP Auth
6.1.1. 默认配置
6.1.2. 设置用户名和密码
6.1.3. 禁用 Security
6.2. Spring boot with Spring security
6.2.1. Maven
6.2.2. Reource
6.2.3. Application
6.2.4. WebSecurityConfigurer
6.2.5. RestController
6.2.6. 测试
6.2.7. Spring + Security + MongoDB
6.3. Spring Boot with Web Security
6.3.1. EnableWebSecurity
6.3.2. Web静态资源
6.3.3. 正则匹配
6.3.4. 登陆页面,失败页面,登陆中页面
6.3.5. CORS
6.3.6. X-Frame-Options 安全
6.4. 访问控制列表(Access Control List,ACL)
6.4.1. antMatchers
6.4.2. HTTP Auth
6.4.3. Rest
6.4.4. hasRole
6.4.5. hasAnyRole()
6.4.6. withUser
6.5. Spring Authorization Server
6.5.1. Oauth2 协议
6.5.2. Maven 依赖
6.5.3. Spring cloud with Oauth2
7. Spring Cloud
7.1. Spring Cloud 相关的 application.properties 配置
7.1.1. 启用或禁用 bootstrap
7.1.2. bootstrap.properties 配置文件
7.2. Spring Cloud Config
7.2.1. Maven 项目 pom.xml 文件
7.2.2. Server
7.2.3. Client
7.2.4. Config 高级配置
7.2.5. Old
7.3. Spring Cloud Consol
7.3.1. Spring Cloud Consul 配置
7.3.2. Maven 父项目
7.3.3. Consul 服务生产者
7.3.4. Consul 服务消费者
7.3.5. Openfeign
7.4. Spring Cloud Netflix
7.4.1. Eureka Server
7.4.2. Eureka Client
7.4.3. Feign client
7.4.4. 为 Eureka Server 增加用户认证
7.4.5. Eureka 配置项
7.4.6. ribbon
7.4.7. 获取 EurekaClient 信息
7.4.8. Zuul
7.5. Openfeign
7.5.1. Openfeign 扫描包配置
7.5.2. 用户认证
7.5.3. 应用实例
7.5.4. 配置连接方式
7.5.5. 配置手册
7.6. Spring Cloud Gateway
7.6.1. Gateway 例子
7.6.2. 路由配置
7.7. Spring Cloud Stream
7.8. Spring Cloud Bus
7.9. Spring Cloud Sleuth
7.10. Spring Cloud with Kubernetes
7.10.1. Config
7.10.2. 注册发现
7.11. Spring Cloud Alibaba
7.11.1. 安装 Nacos
7.11.2. Kubernetes 部署微服务
7.11.3. Nacos 配置中心/注册中心代码实例
7.11.4. FAQ
7.12. FAQ
7.12.1. Cannot execute request on any known server
7.12.2. @EnableDiscoveryClient与@EnableEurekaClient 区别
7.12.3. Feign请求超时
7.12.4. 已停止的微服务节点注销慢或不注销
7.12.5. Feign 启动出错 PathVariable annotation was empty on param 0.
7.12.6. Feign 提示 Consider defining a bean of type 'common.feign.Cms' in your configuration.
7.12.7. Load balancer does not have available server for client
7.12.8. Eureka Client (Dalston.SR1)
7.12.9. Config Server(1.3.1.RELEASE)
8. Tomcat Spring 运行环境
8.1. Maven
8.2. Spring Boot Quick start
8.2.1. 创建项目
8.2.2. pom.xml
8.2.3. Controller
8.3. Spring MVC configuration
8.4. Tomcat
8.5. 集成 Mybatis
8.5.1. pom.xml
8.5.2. properties
8.5.3. dataSource
8.5.4. SqlSessionFactory
8.5.5. Mapper 扫描
8.5.6. Mapper 单一class映射
8.5.7. Service
8.5.8. 测试实例
9. Miscellaneous
9.1. 阿里云 OSS - STS进行临时授权访问获取 HTTPS 地址
10. FAQ
10.1. org.hibernate.dialect.Oracle10gDialect does not support identity key generation
10.2. No identifier specified for entity
10.3. Could not read document: Invalid UTF-8 middle byte 0xd0
10.4. java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
10.5. Field javaMailSender in cn.netkiller.rest.EmailRestController required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.
10.6. org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "172.16.0.3", user "test", database "test ", SSL off
10.7. Spring boot 怎样显示执行的SQL语句
10.8. Cannot determine embedded database driver class for database type NONE
10.9. Spring boot / Spring cloud 时区差8个小时
10.10. @Value 取不到值
10.11. Spring boot 2.1.0
10.12. Field authenticationManager in cn.netkiller.oauth2.config.AuthorizationServerConfigurer required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found.
10.13. 打印 Bean 信息
10.14. The dependencies of some of the beans in the application context form a cycle
10.15. no main manifest attribute, in /srv/job-admin.jar
1. 附录
1.1. Springboot example

范例清单

2.1. Spring boot with Velocity template (pom.xml)
2.2. RedisTemplate
2.3. Example Spring boot with Oracle
2.4. Spring boot with Apache kafka.
2.5. Spring boot with Apache kafka.
2.6. Test Spring Kafka
2.7. Spring boot with Email (pom.xml)
5.1. Spring Data Redis Example
5.2. Spring Data MongoDB - springframework-servlet.xml
7.1. Share feign interface.
8.1. MyBatis