本地的SpringBoot项目平时起都没问题,想验证个功能点的时候突然起不来,报这个错误
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).
看了下不是因为数据库连接的问题,再看profile也激活了,
试了各种方式都不行,然后百思不得其解。苦思冥想中试了下不经过编译直接运行,发现竟然好使了,灵机一动看下编译出来的target文件。
经过mvn命令:
不经过mvn命令直接启动:
从上面图中可以看出问题了,经过mvn命令的缺少了配置文件,所以运行不起来,
解决办法是:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> ----------------------指定将resources中配置文件加载到target----------------------- <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> </includes> </resource> --------------------------指定将resources中配置文件加载到target------------------- </resources> </build>
希望能帮助到遇到同样问题的你(#^.^#)~。