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