
springboot
逆势生长
无法将我毁灭,则必将使我强大
展开
-
springboot中给restTemplate自定义过期时间
1.配置restTemplate,因为我的项目已经存在restTemplate的配置,新的restTemplate是给一部分rest接口调用时使用的,所以自建一个注解@RestType来区分使用的哪一个:@Configurationpublic class RestConfig { @Bean @Primary public RestTemplate restTemplate(){ return new RestTemplate(); }原创 2021-02-01 15:53:03 · 904 阅读 · 1 评论 -
@Cacheable注解使用 - 缓存查询数据
@Cacheable既作用在方法上,也就用在类上。当作用在方法上是只对该方法有用,作用在类上时,对该类的所有方法都有效。示例:controller: @GetMapping("test_cache") public String testCache(@RequestParam String flag){ String s = countryService.testCache(flag); return s; }service:S.原创 2020-07-31 23:59:07 · 2704 阅读 · 4 评论 -
@Async 注解使用小例子
@Target({ElementType.TYPE, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Async { String value() default "";}@Async 用于异步调用,由上面源码可知:原创 2020-07-31 23:43:47 · 549 阅读 · 0 评论 -
Assert 断言 使用简列及注意点
assert 不仅是个报错函数,其表达的意思就是,程序在我的假设条件下,能够正常良好的运作,其实就相当于一个 if 语句,但是更加简洁;示例:@GetMapping("test_assert") public String testAssert(Integer id){ Assert.isTrue(id<=0,"id 非法"); Country country = countryService.getById(id); return原创 2020-07-31 19:46:15 · 357 阅读 · 0 评论 -
springboot 实现 RabbitMq 主题模式(Topic) 案列
目录1.先加入maven依赖2. 在 application.yml 中配置rabbitmq的 连接信息:3.创建生产者4.创建两个消费者5.测试类中测试结果 :控制台打印出消费者的log日志:可见,消费者1 绑定交换机的路由键为 key = "hello.queue.1" ,因此消费了5条奇数类型的消息; 消费者2 绑定交换机的路由键为 key = "hello.queue.*" ,两种都可以匹配上,因此消费了所有消息;1.先加入maven依赖...原创 2020-06-23 14:32:11 · 834 阅读 · 0 评论 -
springboot 实现 RabbitMq 路由模式(Routing) 案列
1.先加入maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency>2. 在 application.yml 中配置rabbitmq的 连接信息...原创 2020-06-23 13:42:08 · 1021 阅读 · 3 评论 -
springboot 实现 RabbitMq 订阅发布模式(Publish/Subscribe) 案列
目录1.先加入maven依赖2. 在 application.yml 中配置rabbitmq的 连接信息:3.创建生产者4.创建两个消费者6.测试类中测试结果 :控制台打印出消费者的log日志:可见,两个消费者都收到了生产者发的5条消息1.先加入maven依赖 <dependency> <groupId>org.springframework.boot</groupId> .原创 2020-06-23 11:18:01 · 1417 阅读 · 0 评论 -
springboot 实现 RabbitMq 工作模式(Work queues) 案列
1.先加入maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency>2. 在 application.yml 中配置rabbitmq的 连接...原创 2020-06-22 23:03:52 · 1898 阅读 · 1 评论 -
springboot 实现 RabbitMq 简单模式 案列
springboot 中使用 rabbitmq简单模式 只需要几点简单配置即可;目录springboot 中使用 rabbitmq简单模式 只需要几点简单配置即可;1.先加入maven依赖2. 在 application.yml 中配置rabbitmq的 连接信息:3.队列配置,启动时创建队列4.创建生产者5.创建消费者6.测试类中测试结果 :控制台打印出消费者的log日志:receiver:rabbit-mq-test1.先加入ma...原创 2020-06-22 19:59:34 · 699 阅读 · 0 评论 -
为什么springboot中有的依赖不用加版本号,有的依赖却必须加
springboot项目中使用maven管理依赖,有些依赖不用加版本号maven就可以自动识别下载,而有些依赖不加版本号会直接报红。效果展示:下面以 lombook 和 mybatisPlus的依赖为例演示:原因说明:我们新建springboot项目时,生成的pom文件里有这样一段代码:<parent> <groupId>org.springframework.boot</groupId> <artifactId>spr.原创 2020-05-12 14:41:06 · 6595 阅读 · 0 评论 -
springboot+websocket 实现简单的订阅广播,定时推送消息
1.加入依赖<!--websocket--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactI...原创 2019-11-11 11:39:05 · 2037 阅读 · 1 评论 -
springboot 2.0 整合 redis 使用StringRedisTemplete
第一步: 在linux上安装redis linux服务器的系统为centos7 ,具体安装参考https://www.cnblogs.com/rslai/p/8249812.html第二步: 在pom.xml文件中加入依赖<!-- 添加redis支持--><dependency> <groupId>org.spri...原创 2019-06-21 10:09:56 · 272 阅读 · 0 评论