package com.example.boot3.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @Autowired private StringRedisTemplate redisTemplate; @GetMapping("/hello") public String Hello(){ return "Hello"; } @GetMapping("/incr") public String incr(){ Long haha = redisTemplate.opsForValue().increment("haha"); return "增加后的为" + haha; } }
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.2.1
com.example
boot3
0.0.1-SNAPSHOT
boot3
boot3
17
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
com.alibaba
druid
1.2.16
org.springframework.boot
spring-boot-starter-data-redis
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
server: port: 9999 spring: servlet: multipart: max-file-size: 10MB data: redis: host: 192.168.92.129 port: 6379 database: 0 password: abc123 lettuce: pool: max-active: 8 max-wait: -1ms max-idle: 8 min-idle: 0 timeout: 5000
package com.example.boot3; import com.example.boot3.bean.*; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @ComponentScan("com.example")//改变包扫描路径 @SpringBootApplication(scanBasePackages = "com.example.boot3")//手动指定扫描包位置 public class Boot3Application { public static void main(String[] args) { var ioc = SpringApplication.run(Boot3Application.class, args); // for (String name : ioc.getBeanDefinitionNames()) { // System.out.println(name); // } // Object user = ioc.getBean("user"); // Object user1 = ioc.getBean("user"); // System.out.println(user == user1); // System.out.println(ioc.getBean("fastsqlException")); for (String s : ioc.getBeanNamesForType(Cat.class)) { System.out.println(s); } for (String s : ioc.getBeanNamesForType(Dog.class)) { System.out.println(s); } for (String s : ioc.getBeanNamesForType(User.class)) { System.out.println(s); } Object pig = ioc.getBean("pig"); System.out.println(pig); // for (String s : ioc.getBeanNamesForType(Sheep.class)) { // System.out.println(s); // } Object sheep = ioc.getBean(Sheep.class); System.out.println(sheep); } }
到此这篇yml文件配置redis(yaml配置redis)的文章就 介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/rfx/49452.html