当前位置: 首页 > wzjs >正文

直播做网站宁波网站优化

直播做网站,宁波网站优化,怎么在拼多多开网店,网页制作软件哪里有项目场景 基于Spring Cloud微服务的商城系统。 使用Nacos进行统一配置管理,在bootstrap.xml中读取配置参数。 问题描述 购物车微服务可以读取Nacos中的共享mybatis配置,商品管理微服务却读不到,启动报错提示无法配置数据库源: …

项目场景

基于Spring Cloud微服务的商城系统。
使用Nacos进行统一配置管理,在bootstrap.xml中读取配置参数。


问题描述

购物车微服务可以读取Nacos中的共享mybatis配置,商品管理微服务却读不到,启动报错提示无法配置数据库源:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2025-03-12 08:37:45.930 ERROR 11556 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : ***************************
APPLICATION FAILED TO START
***************************Description:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver classAction:Consider the following:If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.If you have database settings to be loaded from a particular profile you may need to activate it (the profiles local are currently active).Process finished with exit code 1

可能的原因分析

检查bootstrap.yaml中的Nacos服务器地址和共享配置文件名字:

spring:application:name: item-service  # 微服务名称profiles:active: devcloud:nacos:server-addr: 192.168.119.128:8848config:file-extension: yaml  # 文件后缀名shared-configs:   # 共享配置- data-id: shared-jdbc.yaml # 共享mybatis配置- data-id: shared-log.yaml  # 共享日志配置- data-id: shared-swagger.yaml  # 共享日志配置- data-id: shared-seata.yaml

检查Nacos配置文件shared-jdbc.yaml
Nacos配置管理

spring:datasource:url: jdbc:mysql://${hm.db.host:192.168.119.128}:${hm.db.port:3306}/${hm.db.database}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghaidriver-class-name: com.mysql.cj.jdbc.Driverusername: ${hm.db.un:root}password: ${hm.db.pw:123}
mybatis-plus:configuration:default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandlerglobal-config:db-config:update-strategy: not_nullid-type: auto

检查application.yaml中的数据库名称:

server:port: 8081
hm:db:database: hm-itemswagger:title: "商城商品服务接口文档"package: com.hmall.item.controller

检查pom.xml的相关依赖:

		<!--Nacos统一配置管理--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!--读取bootstrap文件--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId></dependency>

疑问:为什么要把配置参数写在bootstrap.yaml中,而不直接写在application.yaml中?

  1. 加载顺序
    • bootstrap.yaml在Spring Boot应用启动时,bootstrap.yaml会先于application.yaml加载。这使得Nacos配置中心的相关参数(如服务器地址、命名空间等)能在应用启动初期被读取,确保后续配置加载时Nacos已准备就绪。
    • application.yamlapplication.yaml的加载在bootstrap.yaml之后,适合存放应用自身的配置。
  2. 配置优先级
    • bootstrap.yamlbootstrap.yaml中的配置优先级高于application.yaml,确保Nacos配置参数不会被application.yaml中的配置覆盖
  3. 环境隔离
    • bootstrap.yaml:通常用于与环境相关的配置,如Nacos服务器地址等,便于在不同环境中切换。
    • application.yaml:适合存放与环境无关的应用配置。
  4. 配置中心集成
    • bootstrap.yaml:在集成配置中心时,bootstrap.yaml用于指定配置中心的位置和认证信息,确保应用启动时能正确连接到配置中心并获取配置。

总结:将Nacos配置参数放在bootstrap.yaml中,主要是为了确保这些配置能在应用启动初期加载,并且不会被其他配置覆盖,同时便于环境隔离和配置中心集成。

http://www.dtcms.com/wzjs/309420.html

相关文章:

  • 动漫网站设计与实现网站推广的常用方法有哪些
  • 苹果网站模版网站流量排名
  • 个人网站模板之家西安网站seo公司
  • 随便玩玩在线制作网站抖音怎么运营和引流
  • 株洲能建网站的有哪些外链代发
  • 网站没有做301定向如何做推广
  • 做网站需要多少人百度网站官网入口网址
  • 省市网站建设考核标准要求武汉大学人民医院怎么样
  • 网站建设排版百度新闻最新消息
  • 网站建设 厦门东莞seo建站
  • 北京的设计院排名seo是什么字
  • 商城开发网站怎样在网上推广自己的产品
  • 宁德企业网站建设门户网站推广方案
  • 宜昌医院网站建设seo搜索引擎
  • 厦门知名做企业网站设计的公司百度网址大全网站
  • 政府网站建设的作用百度搜索引擎的功能
  • 南京大型门户网站建设营销模式和营销策略
  • 做问卷的网站有哪些seo综合查询爱站
  • typecho移植wordpress上海seo优化
  • 燕郊网站开发介绍产品的营销推文
  • 工信部官网查询系统查询手机广西seo公司
  • 网站推广方案设计网站seo优化方案项目策划书
  • 做酱菜网站百度网站入口链接
  • 找谁做网站比较好一个企业该如何进行网络营销
  • 八大电商平台是哪几家杭州seo俱乐部
  • 厦门专业网站设计网络推广是做什么的
  • 网站建设制作设计公司佛山经典seo伪原创
  • 攸县政府门户网站廊坊关键词排名优化
  • 免费版网站建设合同上海网络推广外包
  • 佛山专业的网站建设搜索引擎营销特点是什么