测试代码:
package com.qzcsbj.demo;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @description : <描述>
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class MyTest {
@Autowired
private StringRedisTemplate stringRedisTemplate;
// 使用StringRedisTemplate对象
@Test
public void test1(){
stringRedisTemplate.opsForValue().set("job","dev");
System.out.println("set字符串完成。");
String job = stringRedisTemplate.opsForValue().get("job");
System.out.println("获取到的job: " + job);
}
}
![](https://img-blog.csdnimg.cn/img_convert/821f97b54dbf5fdbf1b9a7169429e2c2.png)
方案:
把@Test导包:import org.junit.jupiter.api.Test;
改为:import org.junit.Test;