Springboot的坑


SpringBoot关于依赖注入的坑很多,记录一下

  • @Value变量为什么是null?
    @Value取值为NULL的解决方案
    How to get the content of file properties in Spring Boot

  • 我的redisUtil为什么是null?
    redisUtil类如何在Redis与springboot中使用
    解决:SpringBoot中注入StringRedisTemplate异常

2021-11-29 21:18:12.938  WARN 10175 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'wechatTokenUtil'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'wechatTokenUtil' defined in file [/Users/linjiashen/IdeaProjects/MetasequoiaService/shuishan-wechat-server/target/classes/com/wechat/official/util/WechatTokenUtil.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisUtil': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'redisTemplate' is expected to be of type 'org.springframework.data.redis.core.StringRedisTemplate' but was actually of type 'org.springframework.data.redis.core.RedisTemplate'