首页 > 数据库 >org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisCo

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisCo

时间:2024-07-22 17:53:01浏览次数:10  
标签:creating service autowired redisConfig spring 192.168 server port order

场景:

springcloud 的服务 service-order 启动和运行正常

application.yml内容

server:
  port: 8007
  servlet:
    context-path: /service-order

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.56.30:8848
  application:
    name: service-order  
  redis:
    host: 192.168.56.30
    port: 6379
    database: 0
    password: root

---
spring:
  profiles: 8007
server:
  port: 8007
---
spring:
  profiles: 8008
server:
  port: 8008

修改使用nacos配置中心,将配置信息移到配置中心,启动后报错:

bootstrap.yml

spring:
  cloud:
    nacos:
      config:
        server-addr: 192.168.56.30:8848
        namespace: devId
        file-extension: yaml
  application:
    name: service-order
  profiles: #指定使用的配置文件
    active: dev

# service-order-dev.yaml

nacos配置中心新建配置项:service-order-dev.yaml

server:
  port: 8007
  servlet:
    context-path: /service-order

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.56.30:8848
  application:
    name: service-order  
  redis:
    host: 192.168.56.30
    port: 6379
    database: 0
    password: root

---
spring:
  profiles: 8007
server:
  port: 8007
---
spring:
  profiles: 8008
server:
  port: 8008

 

报错信息:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.redis.host' in value "${spring.redis.host}"

 

报错原因:

配置信息没有加载

 

问题排查

1 排查bootstrap.yml的配置问题

发现都是正确的,那么就是新的

2 查看 service-order-dev.yaml 配置是否正确

这里的内容是从原来的application.yml完全拷贝,原来的程序运行正常

但是仔细一看配置最后有 --- 三个破折号,这个是文件分割的标识。

而nacos配置中心,是一个文件一个内容,这样会产生异常

 

解决问题:

需要删除最后 --- 的几行

最终 service-order-dev.yaml 配置信息如下:

server:
  port: 8007
  servlet:
    context-path: /service-order

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.56.30:8848
  application:
    name: service-order  
  redis:
    host: 192.168.56.30
    port: 6379
    database: 0
    password: root

这时启动正常。

 

总结:

出现下面问题时,一般需要查看配置文件是否有错误,是否生效

Could not resolve placeholder 'spring.redis.host' in value "${spring.redis.host}"

 

标签:creating,service,autowired,redisConfig,spring,192.168,server,port,order
From: https://www.cnblogs.com/etangyushan/p/18316547

相关文章

  • 揭秘@Autowired:手把手教你复刻Spring依赖注入魔法
    文章目录手写一个@Autowired注解实现自动注入@Autowired注解的作用@Autowired的实现原理手写一个@MyAutowired注解定义@MyAutowired注解创建注解处理器集成自定义处理器总结@Autowired主要功能@Autowired实现原理手写@MyAutowired注解注意事项手写一个@Autowir......
  • [1028] Creating your very own Python library
    Ah,creatingyourveryownPythonlibrary—howexciting!......
  • Spring推荐使用构造注入而不使用 @Autowired 注解
    参考:https://www.youtube.com/watch?v=CT8dbbe783shttps://blog.csdn.net/qq_43371556/article/details/123529701https://blog.csdn.net/qq_33721382/article/details/104071801https://blog.csdn.net/fudaihb/article/details/139231192什么是依赖注入DI(Dependency......
  • @Autowired和@Resource有哪些区别
    一、注解的作用@Autowired和@Resource都是用来实现Bean的自动注入功能。二、@Autowired和@Resource的区别1、所属的包不同@Autowired是Spring的注解。@Resource是JSR-250的注解。IDEA有时候会在@Autowired注解上面提示Fieldinjectionisnotrecommended(字段注入是......
  • 015 Creating First C# App using Visual Studio
    CreatingFirstC#App示例代码Program.csclassSample{  staticvoidMain()  {    System.Console.WriteLine("Hello");    System.Console.ReadKey();  }}......
  • @AutoWired和@Resource的区别
    @AutoWired和@Resource的区别来源不同:@AutoWired是Spring提供的注解.@Resource是JavaEE提供的,来源于java.annotation包,是JSR-250的一部分,所以,@Resource不是Spring特有的,它可以使用在所有遵循JavaEE标准的项目中。注入方式不同:@AutoWired默认是按照byType进行依赖注......
  • Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
    这个错误信息表明在初始化blogServiceImpl这个bean时遇到了问题,具体原因是Java类org.aspectj.util.PartialOrder$PartialComparable没有找到。这通常意味着你的项目中缺少AspectJ相关的依赖或配置。AspectJ是一个面向切面编程(AOP)的框架,它需要特定的编译器和运行时库。要......
  • threejs入门2:Creating a scene
    参考:https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-sceneThegoalofthissectionistogiveabriefintroductiontothree.js.Wewillstartbysettingupascene,withaspinningcube.Aworkingexampleisprovidedatthebottomof......
  • Error creating bean with name 'userServiceImpl': Unsatisfied dependency expresse
     原因是:Property'sqlSessionFactory'or'sqlSessionTemplate'arerequired,检查一下这两个类是干什么的:SqlSessionFactory是MyBatis的重要对象之一,是创建SqlSession的工厂。SqlSessionTemplate是MyBatis-Spring的核心,是MyBatis为了接入Spring提供的Bean,这个......
  • 3_@Autowired注解失效分析
    1.Aware接口Aware接口提供了一种[内置]的注入手段,可以注入BeanFactory,ApplicationContext。内置的注入和初始化不受扩展功能的影响,总会被执行,因此Spring框架的内部类常使用它们。InitializingBean接口提供了一种[内置]的初始化手段。Aware的作用就是注入与容器相关的信......