欧阳先僧 2021-03-21 19:34 采纳率: 0%
浏览 641

使用consul作为配置中心时启动报错

Connected to the target VM, address: '127.0.0.1:64697', transport: 'socket'
19:30:58.263 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.cloud.consul.config.ConsulConfigDataMissingEnvironmentPostProcessor$ImportException: No spring.config.import set
    at org.springframework.cloud.consul.config.ConsulConfigDataMissingEnvironmentPostProcessor.postProcessEnvironment(ConsulConfigDataMissingEnvironmentPostProcessor.java:62)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
    at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
    at java.util.ArrayList.forEach(ArrayList.java:1259)
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:362)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
    at com.example.springtestproject.SpringTestProjectApplication.main(SpringTestProjectApplication.java:10)
19:30:58.266 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - 

***************************
APPLICATION FAILED TO START
***************************

Description:

No spring.config.import property has been defined

Action:

Add a spring.config.import=consul: property to your configuration.
    If configuration is not required add spring.config.import=optional:consul: instead.
    To disable this check, set spring.cloud.consul.config.enabled=false or 
    spring.cloud.consul.config.import-check.enabled=false.

Disconnected from the target VM, address: '127.0.0.1:64697', transport: 'socket'

Process finished with exit code 1

  • 写回答

1条回答 默认 最新

  • 欧阳先僧 2021-03-21 19:38
    关注
    #bootstrap.yml
    spring:
    #  profiles:
    #    active: dev
      application:
        name: ms-user
      cloud:
        consul:
          config:
            # 使用consul 作为配置中心,格式为yaml
            format: yaml
            enabled: true
          host: localhost
          port: 8500
    # application.properties
    server:
      port: 8081
    spring:
    #  profiles:
    #    active: dev
      datasource:
        url: jdbc:mysql://127.0.0.1:3306/ms_user
        username: root
        password: root
        driver-class-name: com.mysql.cj.jdbc.Driver
      jpa:
        hibernate:
        # 让 hibenate 不去操作表结构 ,否则启动时会自动建表
          ddl-auto: none
    package com.example.springtestproject.controller;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class TestController {
        @Value("${first.config:dev}")
        private String profile;
    
        @GetMapping("/getProfile")
        public String getProfile(){
            return this.profile;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路