# springboot **Repository Path**: tangcco/springboot ## Basic Information - **Project Name**: springboot - **Description**: springboot demo - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-12-25 - **Last Updated**: 2022-06-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # springboot-demo > springboot-demo ### [01.idea ](demo01) ​ idea 快速构建 springboot项目 ### [02.官网 ](demo02) ​ 官网 构建 springboot项目 ### [03.maven ](demo03) ​ maven 构建 springboot项目 ### [04.DevTools](demo04) ​ DevTools ​ springboot全局配置文件 springCloud场景下使用 - bootstrap.yaml - bootstrap.yml - bootstrap.properties springboot配置文件 单体应用场景下使用 - application.yaml - application.yml - application.properties application.yaml > application.yml > application.properties | 路劲 | 说明 | | ------------------- | ------------------------------------------------------ | | file:./config/ | 工程文件夹下的config目录。 | | file:/ | 工程文件夹目录,如果是maven项目那么和pom.xml是一个层级 | | classPath:/config/ | 工程 classPath文件夹下的config文件夹 | | classPath:/ | 工程classpath文件夹 | ### [05.Intercepter](demo05) ​ 拦截器 ``` preHandle、postHandle与afterCompletion preHandle 调用时间:Controller方法处理之前 执行顺序:链式Intercepter情况下,Intercepter按照声明的顺序一个接一个执行 若返回false,则中断执行,注意:不会进入afterCompletion postHandle 调用前提:preHandle返回true 调用时间:Controller方法处理完之后,DispatcherServlet进行视图的渲染之前,也就是说在这个方法中你可以对ModelAndView进行操作 执行顺序:链式Intercepter情况下,Intercepter按照声明的顺序倒着执行。 备注:postHandle虽然post打头,但post、get方法都能处理 afterCompletion 调用前提:preHandle返回true 调用时间:DispatcherServlet进行视图的渲染之后 多用于清理资源 ``` ### [06.servlet](demo06) springboot中使用Listener、Filter、Servlet ### [07.freemarker](demo07) springboot整合freemarker ### [08.durid](demo08) springboot整合jdbc durid ### [09.mybatis](demo09) springboot整合mybatis ### [10.mybatis plus](demo10) springboot整合 freemarker mybatis plus ### [11.thymeleaf](demo11) springboot整合 thymeleaf mybatis plus ### [12.jwt](demo12) springboot整合jwt ### [13.redis](demo13) springboot整合redis ### [14.mongodb](demo14) springboot整合mongodb ### [15.websocket](demo15) springboot整合websocket ### [16.quartz](demo16) springboot整合quartz ### [17.mq](demo17) springboot整合mq ### [18.FastDFS](demo18) springboot整合 原生 FastDFS 和 tobato 推荐使用 [tobato](https://github.com/MarsNumberOne/FastDFS-Demo.git) ### [19.Swagger](demo19) springboot整合Swagger ### [20.Validation](demo20) springboot 自定义错误页面 整合数据校验 ```java @NotBlank 字符串不能为空 @NotNull 基本数据类型对象类型的对象不能为空 @NotEmpty 集合不能为空 @Length 爬到字符串长度(最大或者最小) @Max 最大值 @Min 最小值 ``` ### [21.健康状态](demo21) http://localhost/actuator ```json { "_links": { "self": { "href": "http://localhost/actuator", "templated": false }, "health-path": { "href": "http://localhost/actuator/health/{*path}", "templated": true }, "health": { "href": "http://localhost/actuator/health", "templated": false }, "info": { "href": "http://localhost/actuator/info", "templated": false } } } ``` http://localhost/actuator/health ```json { "groups": [], "status": { "code": "UP", "description": "" } } ``` Actuator监控分成两类:原生端点和用户自定义扩展端点,原生的主要有: | 路径 | 描述 | | ------------ | ------------------------------------------------------------ | | /autoconfig | 提供了一份自动配置报告,记录哪些自动配置条件通过了,哪些没通过 | | /beans | 描述应用程序上下文里全部的Bean,以及它们的关系 | | /env | 获取全部环境属性 | | /configprops | 描述配置属性(包含默认值)如何注入Bean | | /dump | 获取线程活动的快照 | | /health | 报告应用程序的健康指标,这些值由HealthIndicator的实现类提供 | | /info | 获取应用程序的定制信息,这些信息由info打头的属性提供 | | /mappings | 描述全部的URI路径,以及它们和控制器(包含Actuator端点)的映射关系 | | /metrics | 报告各种应用程序度量信息,比如内存用量和HTTP请求计数 | | /shutdown | 关闭应用程序,要求endpoints.shutdown.enabled设置为true | | /trace | 提供基本的HTTP请求跟踪信息(时间戳、HTTP头等) | ### [springbootAdminServer](admin_server) server坐标 ```xml de.codecentric spring-boot-admin-starter-server 2.3.1 ``` client坐标 ```xml de.codecentric spring-boot-admin-starter-client 2.3.1 org.springframework.boot spring-boot-starter-actuator ``` springoot客户端配置文件 ```yaml spring: application: name: admin-client boot: admin: client: url: http://localhost:2021 #客户端指定服务器端地址 management: endpoint: health: show-details: ALWAYS ``` 事件日志: ```json { "registration": { "name": "admin-client", "managementUrl": "http://phoenix:80/actuator", "healthUrl": "http://phoenix:80/actuator/health", "serviceUrl": "http://phoenix:80/", "source": "http-api", "metadata": { "startup": "2021-01-10T18:57:09.0117091+08:00" } } } ``` ```json { "statusInfo": { "status": "OFFLINE", "details": { "exception": "org.springframework.web.reactive.function.client.WebClientRequestException", "message": "failed to resolve 'phoenix' after 4 queries ; nested exception is java.net.UnknownHostException: failed to resolve 'phoenix' after 4 queries " } } } ``` ```json { "registration": { "name": "admin-client", "managementUrl": "http://phoenix:80/actuator", "healthUrl": "http://phoenix:80/actuator/health", "serviceUrl": "http://phoenix:80/", "source": "http-api", "metadata": { "startup": "2021-01-10T18:43:44.2392174+08:00" } } } ``` ### [22.SpringDataJPA](demo22) ### logback ```xml                xxx %green(%d{yyyy-MM-dd HH:mm:ss.SSS}) %magenta([%thread]) %highlight(%-5level) %cyan(%logger{36}) - %msg%n ${log.file.path}/query.log true true ${log.file.path}/query.%d{yyyy-MM-dd}.log.gz ${max.history:-30} %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n ${log.file.path}/query.jsp ${file.html.enable} =~ /true/ DENY ACCEPT ${log.file.path}/query.%d{yyyy-MM-dd}.%i.html ${file.html.size:-512MB} 1 ${file.html.size:-512MB} %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg host none ${smtp.host} ${smtp.port} ${smtp.username} ${smtp.password} ${smtp.to} ${smtp.from} 【ERROR】: %logger{0} from %X{host} %date %-5level %logger{35} - %message%n ${smtp.enable} =~ /true/ DENY ACCEPT NOTIFY 1 ${log.file.path}/query-error.log ERROR ACCEPT DENY ${log.file.path}/query-error.%d{yyyy-MM-dd}.log.gz ${max.history:-30} %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n ``` ### [23.SpringSession](demo23)