随笔分类 -  SpringBoot+Spring

SpringBoot+Spring
摘要:1.定义注解FlushRedis 1.1 注解定义 @Target(ElementType.METHOD) // 注解用来修饰方法 @Retention(RetentionPolicy.RUNTIME) // 运行时 @Documented // 文档 public @interface Flush 阅读全文
posted @ 2023-02-03 18:45 SpecialSpeculator 阅读(611) 评论(0) 推荐(0) 编辑
摘要:SpringCache 简化缓存操作代码 是一个框架,实现了基于注解的缓存功能,只需要简单的添加注解,就能实现缓存功能 SpringCache提供了一种抽象,底层可以切换不同的cache实现,具体通过CacheManager接口来统一不同的缓存技术 CacheManager是Spring提供的各种缓 阅读全文
posted @ 2023-01-31 21:28 SpecialSpeculator 阅读(79) 评论(0) 推荐(0) 编辑
摘要:扩展springboot的json数据返回使用的json序列化方式 可以指定时间类型json化后的返回样式 可以指定特殊功能定义,Long类型转成字符串形式返回 自定义序列化转换器,代码范例 import com.fasterxml.jackson.databind.DeserializationF 阅读全文
posted @ 2023-01-27 16:12 SpecialSpeculator 阅读(766) 评论(0) 推荐(0) 编辑
摘要:Servlet过滤器 过滤器由Servlet提供,拦截器是springmvc提供 功能 通过配置过滤器,来实现未登录的用户访问后台页面的时候直接跳转到登录页面 后台代码范例 @Slf4j @WebFilter(filterName = "loginCheckFilter",urlPatterns = 阅读全文
posted @ 2023-01-27 11:04 SpecialSpeculator 阅读(418) 评论(0) 推荐(0) 编辑
摘要:Springboot添加静态资源映射配置 将静态资源解析到指定的路径上 @Slf4j @Configuration public class WebMvcConfig extends WebMvcConfigurationSupport { @Override protected void addR 阅读全文
posted @ 2023-01-21 14:13 SpecialSpeculator 阅读(170) 评论(0) 推荐(0) 编辑
摘要:1.定义注解 @Retention(RUNTIME) // 运行时注解 @Target(METHOD) // 代表注解是修饰在方法上的 public @interface OperationHis { String value(); // 可以指定注解里面的属性字段 OperationType op 阅读全文
posted @ 2023-01-17 17:00 SpecialSpeculator 阅读(152) 评论(0) 推荐(0) 编辑
摘要:提交事务后才执行某些方法, 如果把逻辑直接写到@Transactional修饰的方法内部,有可能功能逻辑里读取到的还是没有被提交到库里的数据,还是脏数据 措施 需要添加事务的回调事件,事件提交完毕后,自动执行 @Transactional @Override public void saveOrUp 阅读全文
posted @ 2023-01-17 16:53 SpecialSpeculator 阅读(119) 评论(0) 推荐(0) 编辑
摘要:1.Transactional注解修饰在非public方法上的时候, 2.被自己类中的别的方法调用 说明: 被注解修饰的方法所在的类,该类中的方法直接互相调用就会失效,只有别的类掉这个类的方法时才会生效 阅读全文
posted @ 2023-01-17 16:50 SpecialSpeculator 阅读(18) 评论(0) 推荐(0) 编辑
摘要:Controller的单元测试 大体代码 import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotat 阅读全文
posted @ 2022-12-08 11:07 SpecialSpeculator 阅读(639) 评论(0) 推荐(0) 编辑
摘要:1.抽象BeanContext,内嵌静态方法 @Component public class BeanContext implements ApplicationContextAware { private static ApplicationContext applicationContext; 阅读全文
posted @ 2021-11-12 13:31 SpecialSpeculator 阅读(490) 评论(0) 推荐(0) 编辑
摘要:1.springboot要版本保持在2.5以上 2.添加跨域配置 CorsConfig import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configur 阅读全文
posted @ 2021-11-11 11:54 SpecialSpeculator 阅读(151) 评论(0) 推荐(0) 编辑
摘要:Async注解 1.自定义使用的线程池 @EnableAsync @Configuration public class AsyncConfig implements AsyncConfigurer { @Bean("customAsyncPool") @Override public Thread 阅读全文
posted @ 2021-11-01 13:44 SpecialSpeculator 阅读(72) 评论(0) 推荐(0) 编辑
摘要:1.Springboot启动原理分析 1.1 继承spring-boot-starter-parent,就相应的继承了一些版本控制的东西 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-star 阅读全文
posted @ 2021-10-29 15:53 SpecialSpeculator 阅读(192) 评论(0) 推荐(0) 编辑
摘要:springboot启动后执行某些动作 1.主要是springboot的启动run方法里调用了callRunners,会去调用实现了ApplicationRunner接口的类的方法 public ConfigurableApplicationContext run(String... args) { 阅读全文
posted @ 2021-10-20 14:28 SpecialSpeculator 阅读(208) 评论(0) 推荐(0) 编辑
摘要:自定义AOP,实现自动捕获方法的执行时间1.自定义Aspect @Component @Aspect public class JournalServiceAspect { private static final Logger logger = LoggerFactory.getLogger(JournalServiceAspect.c 阅读全文
posted @ 2021-10-15 15:57 SpecialSpeculator 阅读(92) 评论(0) 推荐(0) 编辑
摘要:1.RunWith 注解 RunWith 就是一个运行器 可以在单元测试的时候,自动创建spring的应用上下文 2.正确使用 pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-bo 阅读全文
posted @ 2021-06-01 15:39 SpecialSpeculator 阅读(875) 评论(0) 推荐(0) 编辑
摘要:1.说明 Configuration注解的出现就是为了替换xml文件 java配置是通过@Configuration和@Bean注解实现了 @Configuration注解,声明当前是一个配置类,相当于是spring中的一个xml文件 @Bean 注解: 作用在方法上,声明当前方法的返回值是一个Be 阅读全文
posted @ 2021-06-01 15:10 SpecialSpeculator 阅读(1576) 评论(0) 推荐(0) 编辑
摘要:0.ApiException /** * controller exception annotation */ @Retention(RUNTIME) @Target(METHOD) public @interface ApiException { Status value(); } 1.配置全局异 阅读全文
posted @ 2021-06-01 10:47 SpecialSpeculator 阅读(190) 评论(0) 推荐(0) 编辑
摘要:1. Controller接收Date类型的数据 核心使用@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 来将传递过来的时间字符串转化为Date类型 @RestController @RequestMapping("res") public clas 阅读全文
posted @ 2021-06-01 10:24 SpecialSpeculator 阅读(607) 评论(0) 推荐(0) 编辑
摘要:1.使用场景 @Resource和@Autowired都是做bean注入时使用 @Resource是jdk的注解,不是spring的注解;由包javax.annotation.Resource提供,需要导入,但是Spring支持该注解注入 2.相同点,不同点 共同点:两者都可以写在setter方法, 阅读全文
posted @ 2021-05-31 15:57 SpecialSpeculator 阅读(1705) 评论(0) 推荐(0) 编辑

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