今天开发一个微服务的oauth服务,我们用的是consul做配置中心,今天报了一个错误是:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-26 14:55:42.577 ERROR 8888 --- [ 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 class
Action:
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 (no profiles are currently active).
Disconnected from the target VM, address: '127.0.0.1:53565', transport: 'socket'
Process finished with exit code 1
由于这个错误网上很常见,以前也遇见过,我一看知道是什么问题,这个异常大概的意思是我的pom文件中引入的mybatis的左边没有用到,才会报这样的错,同时只要是在启动类上加上如下注解就可以解决:@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})但是尝试了很久还是没能狗解决,因为以前遇见过,也是同样的方法解决的很奇怪。经过出去抽了只眼,我就一直想不明白为什么,但是我突然想到,昨天调整过pom文件,突然我发现少了一个坐标。
解决方法:加上了如下的坐标
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
用consul做配置中心少了这个坐标当然不行了,找了一上午bug,一根烟解决了。
网友评论