随笔分类 -  SpringBoot+Spring

SpringBoot+Spring
摘要:spring的配置类中内嵌一个自己类的静态属性,并提供静态方法,用于外部静态类或者静态方法可以直接获取 核心是定义一个静态属性INSTANCE,类型是配置类的自己 PostConstruct注解修饰init方法,对静态属性赋值为this @Data @Configuration @Configura 阅读全文
posted @ 2025-02-13 11:00 SpecialSpeculator 阅读(4) 评论(0) 推荐(0) 编辑
摘要:分布式限流,依赖redis 实现1个按秒限流的限流器, 知识点:自定义注解,切面,注解的使用 源码 1.创建自定义注解 RateLimit 首先,我们定义一个自定义注解 RateLimit,它包含 code 和 limit 属性。 import java.lang.annotation.Elemen 阅读全文
posted @ 2024-09-03 14:01 SpecialSpeculator 阅读(143) 评论(0) 推荐(0) 编辑
摘要:1.org.junit.Test junit4版本使用 自己项目定义的 <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> </dependency> 单侧中不需 阅读全文
posted @ 2024-08-30 15:57 SpecialSpeculator 阅读(131) 评论(0) 推荐(0) 编辑
摘要:先说结论 接口BeanPostProcessor 更灵活, 可以实现bean生命周期里前,后分别执行某些内容,必须是spring管理的bean才能实现此功能,不加@Component不生效 @Component public class MyBeanPostProcessor implements 阅读全文
posted @ 2024-07-29 16:28 SpecialSpeculator 阅读(23) 评论(0) 推荐(0) 编辑
摘要:核心思想 实现InitializingBean接口,重写afterPropertiesSet方法 范例代码 import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; imp 阅读全文
posted @ 2024-05-22 14:52 SpecialSpeculator 阅读(30) 评论(0) 推荐(0) 编辑
摘要:使用Configuration @Configuration @ConfigurationProperties(prefix = "com.didispace") public class DidispaceProperties { private String title; } 这个Didispa 阅读全文
posted @ 2024-05-21 15:51 SpecialSpeculator 阅读(15) 评论(0) 推荐(0) 编辑
摘要:1.排查每个bean加载时间是否有过长的 @Component public class BeanInitCostTimeBeanPostProcessor implements BeanPostProcessor { private static final Logger logger = Log 阅读全文
posted @ 2024-05-21 15:22 SpecialSpeculator 阅读(363) 评论(0) 推荐(0) 编辑
摘要:1.引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org 阅读全文
posted @ 2024-04-16 13:30 SpecialSpeculator 阅读(27) 评论(0) 推荐(0) 编辑
摘要:统一controller返回对象 package com.xxx.jscaffold.handler; import com.xxx.jscaffold.api.dto.common.Result; import org.springframework.core.MethodParameter; i 阅读全文
posted @ 2024-04-12 14:41 SpecialSpeculator 阅读(26) 评论(0) 推荐(0) 编辑
摘要:1.本地运行 本地run方法运行后 打开swagger,会进入单点登录,输入账户密码通过单点登录 2.普通接口请求 直接使用swagger进行访问测试 并抓取cookie出来 3.需要用户角色身份的 需要开启工具拼接本地请求及本地swagger里获取的cookie头,拼接参数,及请求头 类似如下测试 阅读全文
posted @ 2023-12-07 17:31 SpecialSpeculator 阅读(66) 评论(0) 推荐(0) 编辑
摘要:1.对某些字段指定额外的返回值 核心是使用@JsonProperty("cluster_name") 注解来指定接口返回的时候数据解析的字段 @SerializedName注解是gson格式化输出和解析的时候用来解析的 package delta.api.domain; import com.fas 阅读全文
posted @ 2023-12-07 17:27 SpecialSpeculator 阅读(141) 评论(0) 推荐(0) 编辑
摘要:# 遍历嵌套数据结构 渲染map 中value是list的内容 ``` 0) > 【节点明细】${alarmLevel + ":"}${node.nodeNo}, ``` # 说明 1. 判断nodes是否为null,并判断nodes是否为空map 表达式中调用变量的判断逻辑不能用$符号,必须用() 阅读全文
posted @ 2023-08-01 17:51 SpecialSpeculator 阅读(9) 评论(0) 推荐(0) 编辑
摘要:# spring某些类只有在prod环境生效并加载bean ```java @Profile("prod") // 只有prod的profile环境下,spring才会加载bean到容器中过去 @Component @Slf4j @Profile("prod") public class UmpAl 阅读全文
posted @ 2023-06-29 16:52 SpecialSpeculator 阅读(67) 评论(0) 推荐(0) 编辑
摘要:# Env工具类获取运行时环境 ```java public class EnvConfig { public enum Env { PROD("prod","PROD","生产环境"), UAT("uat","UAT","预发环境"), DEV("dev","DEV","开发环境"); priva 阅读全文
posted @ 2023-06-26 14:13 SpecialSpeculator 阅读(29) 评论(0) 推荐(0) 编辑
摘要:# 1.自定义starter名为my-starter-spring-boot-starter ## 1.1 idea中创建一个maven模块 groupId为com.example artifactId为my-starter-spring-boot-starter 起名规范: 1.官方starter 阅读全文
posted @ 2023-06-12 16:28 SpecialSpeculator 阅读(100) 评论(0) 推荐(0) 编辑
摘要:# 1.AopUtils Aop工具类 ```java Object bean; Class beanClass = AopUtils.getTargetClass(bean); // 获取bean对象的class文件,自动过滤cglib动态代理的代理类 ``` # 2.AnnotitionUtil 阅读全文
posted @ 2023-06-09 15:31 SpecialSpeculator 阅读(83) 评论(0) 推荐(0) 编辑
摘要:# 1.解析注解方式的mq消费者 # 2.注解的定义 ```java @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface JmqListener { String id() default 阅读全文
posted @ 2023-06-08 17:25 SpecialSpeculator 阅读(140) 评论(0) 推荐(0) 编辑
摘要:# @Validated注解 - 修饰controller的入参参数上 - 入参参数内部使用其他细节注解进行判断 # 看样例 ```java @ApiOperation(value = "添加修改ump告警规则") @PostMapping("config") public Result saveO 阅读全文
posted @ 2023-05-29 14:09 SpecialSpeculator 阅读(62) 评论(0) 推荐(0) 编辑
摘要:定义切面,然后匹配controller,around进行log打印 @Slf4j @Component @Aspect public class ControllerLogAspect { @Pointcut("execution(* delta.main.controller..*(..))") 阅读全文
posted @ 2023-05-06 10:10 SpecialSpeculator 阅读(160) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示