记录一下

今天在写为服务项目碰到的错误,如下面所示,只知道创建Error creating bean with name ‘servletEndpointRegistrar’ defined in class path resource失败,在网上也找了一些解决方法,最多的解决答案是说缺少jdbc依赖,要么就是说数据库配置文件出错了,我也比对了下数据库没错,也没缺少jdbc依赖,这说明我的数据库和依赖都没错,我就又比对了下其他service服务,发现就是配置文件多引入了个配置文件

[${project.name}] 2021-09-10 23:21:44,213 ERROR [localhost-startStop-1][Jdk14Logger.java:87] - Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.class]: Unsatisfied dependency expressed through method 'servletEndpointRegistrar' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'management.endpoints.web-org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties': Could not bind properties to 'WebEndpointProperties' : prefix=management.endpoints.web, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'management.endpoints.web.exposure' to org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties$Exposure
[${project.name}] 2021-09-10 23:21:44,240 WARN [main][Jdk14Logger.java:87] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
[${project.name}] 2021-09-10 23:21:44,241 INFO [main][DubboGenericServiceFactory.java:159] - The Dubbo GenericService ReferenceBeans are destroying...
[${project.name}] 2021-09-10 23:21:44,245 INFO [main][Jdk14Logger.java:87] - class org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor was destroying!

我的nacos文件配置是

#HTTP格式配置spring:
http:
  encoding:
    charset: UTF‐8
    force: true
    enabled: true
  messages:
    encoding: UTF‐8
#tomcat头信息(用户ip和访问协议)及访问路径配置
server:
  tomcat:
    remote_ip_header: x‐forwarded‐for
    protocol_header: x‐forwarded‐proto
  servlet:
    context‐path: /lifly
  use‐forward‐headers: true

#服务监控与管理配置,运维相关
management:
  endpoints:
    web:
      exposure:
      include: refresh,health,info,env

这个配置文件就是定义了用户ip和访问路径以及一些与服务监控与管理与运维相关的配置文件,但是service中并没有用到远程调用,我却将该配置文件引入了,我的出错原因是这个,就记录下来了。
我的bootstrap.yml配置文件如下:

server:
  port: 56050 #启动端口 命令行注入
nacos:
  server:
    addr: 127.0.0.1:8848
spring:
  application:
    name: transaction-service
#  main:
#    allow-bean-definition-overriding: true # Spring Boot 2.1 需要设定
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
#        server-addr: ${nacos.server.addr}
        namespace: 339eea59-f7f4-44d0-a3fa-9f1f85bd5b4f
#        cluster-name: COMMON_GROUP
      config:
        server-addr: 127.0.0.1:8848
#        server-addr: ${nacos.server.addr} # 配置中心地址
        file-extension: yaml
        namespace: 339eea59-f7f4-44d0-a3fa-9f1f85bd5b4f  # 默认开发环境郑州区 命令行注入
        group: DEFAULT_GROUP # 聚合支付业务组
        ext-config:
          -
            refresh: true
            data-id: spring-boot-http.yaml # spring boot http配置
            group: COMMON_GROUP # 通用配置组
#          -
#            refresh: true
#            data-id: spring-boot-starter-druid.yaml # spring boot starter druid配置
#            group: COMMON_GROUP # 通用配置组
#          -
#            refresh: true
#            data-id: spring-boot-mybatis-plus.yaml # spring boot mybatisplus配置
#            group: COMMON_GROUP # 通用配置组
#          - refresh: true
#            data-id: spring-boot-redis.yaml # redis配置
#            group: COMMON_GROUP # 通用配置组
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/huiminpay_transaction?useUnicode=true&useSSL=false
    #  url: jdbc:mysql://localhost:3306/huiminpay_merchant_service?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&useUnicode=true
    username: root
    password: 1234
mybatis-plus:
  type-aliases-package: com.huiminpay.transaction.entity
  mapper-locations: classpath:/mapper/*.xml

dubbo:
  scan:
    # dubbo 服务扫描基准包
    base-packages: com.huiminpay
  protocol:
    # dubbo 协议
    name: dubbo
    port: 20893
  registry:
    address: nacos://127.0.0.1:8848
  application:
    qos:
      port: 22250 # dubbo qos端口配置  命令行注入
  consumer:
    check: false
    timeout: 3000
    retries: -1

logging:
  config: classpath:log4j2.xml

我的把那个引入文件注释掉,项目就起来了。再次记录下,也希望对你们有帮助。将下面的引入文件注释掉

 ext-config:
          -
            refresh: true
            data-id: spring-boot-http.yaml # spring boot http配置
            group: COMMON_GROUP # 通用配置组