暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

SpringBoot启动异常和(@Slf4j注解后使用log方法在idea报红)的解决

小马儿博客 2018-12-27
663

(一)SpringBoot启动异常


idea搭建SpringBoot框架的项目。选择组件时,web是必须勾选的,如果你另外选择了Mybatis、Mysql这两个组件,启动DemoApplication时会出现如下报错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2018-12-27 14:42:22.257 ERROR 10540 --- [           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).



Process finished with exit code 1


怎么处理呢?对于初学者,可能有点迷糊,会对自己开发的项目造成无法启动的尴尬,折腾了几天,其实一行代码就可以解决。

需要在启动类的@EnableAutoConfiguration或@SpringBootApplication中添加exclude= {DataSourceAutoConfiguration.class},排除此类的autoconfig。启动以后就可以正常运行。


这是因为添加了数据库组件,所以autoconfig会去读取数据源配置,而我新建的项目还没有配置数据源,所以会导致异常出现。


即:@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})



(二)@Slf4j注解后使用log方法在idea报红


问题:spring boot框架注解@Slf4j后,使用log方法idea报错log找不到,但运行一切正常

原因:依赖包org.projectlombok可以解析spring boot框架下用注解方式来加入快速方法,而idea对这套机制需要lom插件支持

解决:idea安装lom插件后,log不报红

操作:idea -> ctrl+alt+s -> plugin -> 搜索 lom -> 安装后重启即可


扫我,关注一下!





文章转载自小马儿博客,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论