最近在用Springboot2.7整合knife4j-openapi2-spring-boot-starter后,发现无法启动项目直接报错 报错信息 org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException 网上解决办法 当时直接搜索引擎一动,解决办法基本上都是添加一个配置。原因是:Spring Boot 2.6以上引入的新PathPatternParser,需要进行配置,不然整合起来会报错 spring.mvc.pathmatch.matching-strategy=ant-path-matcher 具体问题原因和解决方案 当时以为加上就可以了,结果发现并没有解决问题,问题还是存在,最后网上再次搜索验证,得到的问题原因是和项目引入的其他依赖冲突,当项目当中引入了spring-boot-starter-actuat.... Springboot2.7整合knife4j-openapi2-spring-boot报错Failed to start bean ‘documentationPluginsBootstrapper springboot
Springboot应用整合Prometheus+Grafana进行自定义指标监控 最近需要监控接口的请求数据P90,P99,平均耗时,接口参数包含userId的接口请求数据等等 Springboot应用整合Prometheus+Grafana进行自定义指标监控 运维知识
import freemarker.template.Configuration; import freemarker.template.TemplateModelException; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; /** * freemarker配置 * * @author hjljy * @date 2021/10/15 */ @Component public class FreemarkerConfiguration { private final Configuration configuration; public FreemarkerConfiguration(Configuration configuration) { this.configuration = configuration; } /** * 加载配置变量数据 * * @throws TemplateModelException 模板模型异常 */ @PostCo.... SpringBoot定义Freemaker模板的全局变量 springboot
最近在使用fegin服务调用的时候,同事遇见一个非常困扰的问题,在controller层正常实现fegin接口后,发现无法正常调用服务。 觉得挺好奇的,特此记录一下问题原因和处理方式 原因:在controller层有个方法上面有@Async 注解导致的,(如果不实现接口类,直接使用@Async 请求不会报404) 处理方式:将需要异步的代码放在service层处理!!! 这篇文章给出了问题详细的解释:https://www.cnblogs.com/ming-blogs/p/12951861.html @Async 注解 使用注意事项 没有在@SpringBootApplication启动类当中添加注解@EnableAsync注解。 异步方法使用注解@Async的返回值只能为void或者Future。 没有走Spring的代理类。(即ServiceA里面方法A调用方法B,会不生效!!) 方法一定要从另一个类中调用,也就是从类的外部调用,类的内部调用是无效的,需要先获取其代理类,通过代理类调用异步方法 Spring boot @Async注解导致Controller层在实现接口后,请求报404 杂七杂八
@[toc] 在SpringBoot当中使用Oauth2的时候,发现部分Oauth2的异常无法被springboot的ControllerAdvance全局异常捕获!!! 特此记录下相关的处理方式: Oauth2 自定义异常信息返回(springboot无法全局捕获invalid_client,unauthorized,invalid_token) Bug
SpringBoot+Mybatis-plus:使用枚举接收参数并返回数据 最近项目当中大量使用到枚举,特此记录下项目当中使用枚举的好处,场景,使用方式。 枚举的好处 可读性高, 易理解 统一参数类型,避免传参错误 线程安全,全局唯一,无法修改 枚举使用场景 在实际的使用当中,当某个对象或者某个属性,需要有多个可供选择的状态或者描述,例如人的性别,支付的状态,错误的类型等等,都可以使用枚举。 枚举在项目中的使用 通常在项目当中会存在两种形式的枚举 第一种形式 /** * 性别枚举 * * @author hjljy */ @Getter public enum SexEnum { /** * 性别枚举 */ DEFAULT(-1, "保密"), WOMAN(0, "女"), MAN(1, "男"); @EnumValue //标记存储到数据库的值 @JsonValue //标记json返回的值 private final Integer code; private final String remark; SexEnum(Integer code, String remark) {.... SpringBoot+Mybatis-plus:使用枚举接收参数并返回数据 springboot
最近在返回给前端数据的时候遇到了1 Long类型返回前端精度丢失 2LocalDateTime统一返回时间戳方便前端统一处理的问题,记录下解决方案。 代码如下 环境:springboot2.x ,JDK8 import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import.... Springboot2.x处理Long类型返回前端精度丢失以及LocalDateTime统一返回时间戳 springboot
之前实现了Springboot之Security前后端分离登录 刚好这段时间有空,乘机整合下OAuth2。记录下当中遇到的问题和处理方式。 springboot2.0整合OAuth2并使用JWT作为token springboot
最近在项目当中需要记录接口请求参数以及返回数据,本来是打算通过自定义切面来实现的,后来发现可以使用@ControllerAdvice配合ResponseBodyAdvice来进行记录数据,特此记录,完整代码如下: /** * @author yichaofan * @since 2020/11/20 12:47 * @apiNote 统一打印请求参数和返回参数日志 */ @ControllerAdvice @Slf4j public class ResponseBodyAnalysis implements ResponseBodyAdvice { /** * 参数返回给前端之前进行,可以进行相关的处理例如,记录请求参数,响应参数,封装统一响应参数等操作 * * 源代码注释如下: * Invoked after an {@code HttpMessageConverter} is selected and just before * its write method is invoked. * @param body the body to be written * @param re.... SpringBoot使用@ControllerAdvice配合ResponseBodyAdvice记录接口请求参数以及返回数据 springboot
什么是Spring Security Spring Security是一个功能强大且高度可定制的身份验证和访问控制框架。它是用于保护基于Spring的应用程序的实际标准。 Spring Security是一个框架,致力于为Java应用程序提供身份验证和授权。与所有Spring项目一样,Spring Security的真正强大之处在于可以轻松扩展以满足自定义要求 官方网站:https://spring.io/projects/spring-security#learn Springboot之Security前后端分离登录 springboot
springboot配置文件的读取操作很常见,之前也写过简单的读取配置文件的笔记SpringBoot学习之DAY_02 springboot配置文件信息读取 这篇笔记主要记录下最近在读取配置文件当中的心得和新知识点吧。 Springboot读取自定义属性之集合(list,数组) springboot
SpringBoot整合Druid+全局事务管理+Mybatis-Plus+代码生成器 在springboot开发当中,Druid,全局事务管理,代码生成器都是非常实用的,特此记录下整合的过程 SpringBoot整合Druid+全局事务管理+Mybatis-Plus+代码生成器 无
最近在使用springboot进行切面编程的时候,发现定义切面点有很多种方式,每种方式有每种方式的特点。特此记录 springboot之aop切面execution表达式,@args,@annotation 无
最近在网上看到一个比较好的swagger-ui,swagger自带的UI不是很友好。特此记录下整合过程,并梳理下swagger相关的知识 Springboot之swagger-bootstrap-ui(knife4j) 无