springboot单元测试中Autowired失效

springboot单元测试中Autowired失效

package com.hmdp;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;

@SpringBootTest
public class SpringTest {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void test(){
        stringRedisTemplate.opsForValue().set("k1","v1");
        String k1 = stringRedisTemplate.opsForValue().get("k1");
        System.out.println(k1);
    }
}

img

测试注解@Test 引用应该是import org.junit.jupiter.api.Test;