(1)、引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
<dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.48.Final</version> </dependency>
第二个依赖缺少可能提示:
ClassNotFoundException: io.netty.util.internal.logging.InternalLoggerFactory
(2)、配置redis信息
application.properties中加载redis配置文件
# redis config spring.profiles.include=redis
创建redis配置文件application-redis.properties
### redis config spring.redis.host=192.168.0.35 spring.redis.port=6379 spring.redis.password=123456
(3)、注入redis
@Autowired private StringRedisTemplate redisTemplate;
(4)、操作redis
// 获取authorization String authorization = x2Service.getAuthorization(); // 保存authorization到redis redisTemplate.opsForValue().set(tokenRedisKey, authorization);
// 获取authorization String authorization = (String) redisTemplate.opsForValue().get(tokenRedisKey);
百度教程虽然多,但是2.X都有问题,缺少依赖会报错ClassNotFoundException: io.netty.util.internal.logging.InternalLoggerFactory,折腾一个上午。
java限制1个方法同一时间只能被一个线程访问public synchronized void setOrderPay(){ }加上synchronized 修饰符即可...
(1).final 修饰符通常和 static 修饰符一起使用来创建类常量。(2).父类中的 final 方法可以被子类继承,但是不能被子类重写,声明 final 方法的主要目的是防止该方法的内容被修改。public class Member {  ...
(1).java睡眠函数Thread.sleep(时间); //单位为毫秒(2).java睡眠函数例子Date dNow = new Date(); SimpleDateFormat ft = new&nbs...
System.out.println("当前时间戳(秒): " + System.currentTimeMillis()/1000); System.out.println("当前时间戳(毫秒): " +&nb...
pattern表示正则表达式,接收正则表达式作为参数例子:String content = "my name is gaojiufeng"; String pattern = "....
(7).java方法重载一个类的两个方法拥有相同的名字,但是有不同的参数列表,叫做方法重载,例如public static int sum(int a, int b) { retur...