首先springcloud的官方推荐使用.yml的格式。
然后我就首次使用了.yml格式的配置文件。
然后遇到了首大坑。
首先这是我写的格式:
然后疯狂报错:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-12 14:41:45.766 ERROR 99744 --- [ restartedMain] 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).
Process finished with exit code 0
大致意思是说:
没有指定"url"属性,无法配置任何嵌入式的数据源。
原因是:未能确定合适的驱动程序类。
关键是我的配置文件的内容再三检查了,没有写错一个字母。这我就好奇了。
然后疯狂百度,
有的说是没有用datasource连接数据库。注释掉maven的jar包
还有的说是只是掉启动类的一些参数。在启动类的@EnableAutoConfiguration或@SpringBootApplication中添加exclude = {DataSourceAutoConfiguration.class},排除此类的autoconfig。启动以后就可以正常运行。但是都没有用。
@MapperScan("com.wsc.core.mapper")//映射mapper地址
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
//启动类 SpringBoot
public class Start {
public static void main(String[] args) {
SpringApplication.run(Start.class,args);
}
}
然后还有说是mysql的驱动类jar包出错了,需要手动的添加jar包驱动
依然米有用。
最后发现是格式的错误。
datasource需要个application对齐。
我第一次的格式为:然后找了一上午,没有发现,毕竟第一次使用,错误印象深刻呀。
特此记录!!!防止再犯。