关于:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource的错误

Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

首先,我是在查看consul作为新的服务中心去建立的项目,用于验证
这个错误表示要配置数据源,但是作为一个简单的服务注册中心不需要连接数据库,进行IO;

在这里插入图片描述翻译一下:

描述:

没有指定“url”属性,也无法配置任何嵌入的数据源。

原因:未能确定合适的驱动程序类

但是我的项目中不需要啊:

controller

package com.atguigu.springCloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author webstart
 * @time 2020/4/3/17:55
 * @description
 **/
@RestController
@Slf4j
public class paymentController {



    @Value("${server.port}")
    private  String serverPort;


    @GetMapping(value = "/payment/consul")
    public String consul(){

        return  "springcloud consul"+serverPort+"\t"+ UUID.randomUUID().toString();
    }
}

主启动

package com.atguigu.springCloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
 * @author webstart
 * @time 2020/4/3/18:03
 * @description
 **/
//@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableDiscoveryClient
public class PaymentConsulMain8006{
    public static void main(String[] args) {
        SpringApplication.run(PaymentConsulMain8006.class,args);
    }}

用于解决springboot默认配置数据,找不到数据源的问题,
注解中添加条件

默认自己配置,但是不需要时可以去掉exclude

然后我们就可以得出这个consul可以作为配置中心使用
在这里插入图片描述

关于consul的安装
去官网直接下载一个;

在这里插入图片描述 consul agent -dev

cmd直接安装:
在这里插入图片描述
然后默认启动成功:
http://localhost:8500
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值