当前位置: 首页> 科技> 名企 > 黄页网站软件应用大全_清远清城区_百度网址提交入口_竞价托管怎么做

黄页网站软件应用大全_清远清城区_百度网址提交入口_竞价托管怎么做

时间:2025/7/10 13:15:57来源:https://blog.csdn.net/c_yanxin_ru/article/details/147042161 浏览次数:1次
黄页网站软件应用大全_清远清城区_百度网址提交入口_竞价托管怎么做


java.lang.IllegalArgumentException: template not initialized; call afterPropertiesSet() before using it

Cannot invoke "org.springframework.data.redis.core.StringRedisTemplate.opsForValue()" because "org.example.security.SecurityApplication.template" is null

org.example.security.SecurityApplicationTests#contextLoads

单元测试代码

@SpringBootTest
class SecurityApplicationTests {@Testvoid contextLoads() {
//        String compact = Jwts.builder()
//                .signWith(Jwts.SIG.HS512.key().build())
//                .subject("严欣铷")
//                .expiration(new Date(System.currentTimeMillis() + 7200 * 1000))
//                .compact();
//        System.out.println(compact);RedisTemplate redisTemplate = new RedisTemplate();redisTemplate.afterPropertiesSet();StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();stringRedisTemplate.opsForValue().set("yanxinru","token");System.out.println("添加成功" + stringRedisTemplate);}}

错误代码如上

正确代码


@SpringBootTest
class SecurityApplicationTests {@AutowiredStringRedisTemplate template;  //添加这句代码,自动装载,即可解决文章三处代码报错@Testvoid contextLoads() {
//        String compact = Jwts.builder()
//                .signWith(Jwts.SIG.HS512.key().build())
//                .subject("严欣铷")
//                .expiration(new Date(System.currentTimeMillis() + 7200 * 1000))
//                .compact();
//        System.out.println(compact);template.opsForValue().set("name","yanxinru");System.out.println("添加成功" + template);}}

关键字:黄页网站软件应用大全_清远清城区_百度网址提交入口_竞价托管怎么做

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: