搭建SpringBoot+mybatis+maven集成项目,在运行启动类main函数的时候控制台报出如下错误,启动失败:
-
Error starting ApplicationContext. To display the auto-configuration report re-run your application with
'debug' enabled.
-
2018-
07-
18
16:
57:
29.514 ERROR
17300 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
-
-
***************************
-
APPLICATION FAILED TO START
-
***************************
-
-
Description:
-
-
Cannot determine embedded database driver
class for database type NONE
-
-
Action:
-
-
If
you
want
an
embedded
database
please
put
a
supported
one
on
the
classpath.
If
you
have
database
settings
to
be
loaded
from
a
particular
profile
you
may
need
to
active
it (
no
profiles
are
currently
active).
报错的原因很明显,是我的项目有需要操作数据库的业务,但是数据库配置文件找不到导致数据类型报NONE值。
我的pom.xml配置:
-
<?xml version=
"1.0" encoding=
"UTF-8"?>
-
-
<project xmlns=
"http://maven.apache.org/POM/4.0.0" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
<modelVersion>
4.0.0</modelVersion>
-
-
<groupId>SpringBoot</groupId>
-
<artifactId>SpringBoot</artifactId>
-
<version>
0.0.1-SNAPSHOT</version>
-
<packaging>war</packaging>
-
<name>SpringBoot Maven Webapp</name>
-
<url>http:
//maven.apache.org</url>
-
-
<properties>
-
<project.build.sourceEncoding>UTF-
8</project.build.sourceEncoding>
-
<maven.compiler.source>
1.7</maven.compiler.source>
-
<maven.compiler.target>
1.7</maven.compiler.target>
-
</properties>
-
-
<parent>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-parent</artifactId>
-
<version>
1.5.8.RELEASE</version>
-
<relativePath></relativePath>
-
</parent>
-
-
<resources>
-
<resource>
-
<directory>src/main/java</directory>
-
<includes>
-
<include>**
/*.properties</include>
-
<include>**/*.xml</include>
-
</includes>
-
<filtering>
false</filtering>
-
</resource>
-
<resource>
-
<directory>src/main/resources</directory>
-
<includes>
-
<include>**
/*.properties</include>
-
<include>**/*.xml</include>
-
</includes>
-
<filtering>
false</filtering>
-
</resource>
-
</resources>
-
-
-
-
<dependencies>
-
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter</artifactId>
-
</dependency>
-
<dependency>
-
<groupId>org.mybatis.spring.boot</groupId>
-
<artifactId>mybatis-spring-boot-starter</artifactId>
-
<version>
1.3.1</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-devtools</artifactId>
-
<optional>
true</optional>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-web</artifactId>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-test</artifactId>
-
<scope>test</scope>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-jdbc</artifactId>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-tomcat</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
<exclusions>
-
<exclusion>
-
<artifactId>log4j-over-slf4j</artifactId>
-
<groupId>org.slf4j</groupId>
-
</exclusion>
-
<exclusion>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-tomcat</artifactId>
-
</exclusion>
-
</exclusions>
-
<!-- mysql连接 -->
-
<dependency>
-
<groupId>mysql</groupId>
-
<artifactId>mysql-connector-java</artifactId>
-
<version>
5.1.42</version>
-
</dependency>
-
<!-- mybatis -->
-
</dependencies>
-
-
<build>
-
<finalName>SpringBoot</finalName>
-
<pluginManagement><!--
lock down plugins versions to avoid using Maven
-
defaults (may be moved to parent pom) -->
-
<plugins>
-
<plugin>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-maven-plugin</artifactId>
-
<configuration>
-
<fork>true</fork>
-
</configuration>
-
</plugin>
-
<plugin>
-
<artifactId>maven-clean-plugin</artifactId>
-
<version>3.0.0</version>
-
</plugin>
-
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
-
<plugin>
-
<artifactId>maven-resources-plugin</artifactId>
-
<version>3.0.2</version>
-
</plugin>
-
<plugin>
-
<artifactId>maven-compiler-plugin</artifactId>
-
<version>3.7.0</version>
-
</plugin>
-
<plugin>
-
<artifactId>maven-surefire-plugin</artifactId>
-
<version>2.20.1</version>
-
</plugin>
-
<plugin>
-
<artifactId>maven-war-plugin</artifactId>
-
<version>3.2.0</version>
-
</plugin>
-
<plugin>
-
<artifactId>maven-install-plugin</artifactId>
-
<version>2.5.2</version>
-
</plugin>
-
<plugin>
-
<artifactId>maven-deploy-plugin</artifactId>
-
<version>2.8.2</version>
-
</plugin>
-
<!--This plugin's configuration is used to store Eclipse m2e settings
-
only. It has no influence on the Maven build itself. -->
-
<plugin>
-
<groupId>org.eclipse.m2e</groupId>
-
<artifactId>lifecycle-mapping</artifactId>
-
<version>1.0.0</version>
-
<configuration>
-
<lifecycleMappingMetadata>
-
<pluginExecutions>
-
<pluginExecution>
-
<pluginExecutionFilter>
-
<groupId>
-
org.apache.maven.plugins
-
</groupId>
-
<artifactId>
-
maven-resources-plugin
-
</artifactId>
-
<versionRange>[3.0.2,)</versionRange>
-
<goals>
-
<goal>resources</goal>
-
</goals>
-
</pluginExecutionFilter>
-
<action>
-
<ignore></ignore>
-
</action>
-
</pluginExecution>
-
</pluginExecutions>
-
</lifecycleMappingMetadata>
-
</configuration>
-
</plugin>
-
</plugins>
-
</pluginManagement>
-
</build>
-
</project>
-
项目完整路径:
很奇怪,我将配置文件全部放在resources文件夹下,官方文档也建议将配置文件放在此文件夹下,但是就是找不到我的数据库配置文件,具体原因暂时还不明白。
解决方法:将数据库配置文件(我的是上图resources文件夹下的application.properties)复制到src/java/main目录下,复制后路径如下图所示:
其中resources目录下的application.properties文件可以删除了。
上述操作后成功启动项目,问题解决。
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true"> <use xlink:href="#csdnc-thumbsup"></use> </svg><span class="name">点赞</span> <span class="count">1</span> </a></li> <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true"> <use xlink:href="#icon-csdnc-Collection-G"></use> </svg><span class="name">收藏</span></a></li> <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true"> <use xlink:href="#icon-csdnc-fenxiang"></use> </svg>分享</a></li> <!--打赏开始--> <!--打赏结束--> <li class="tool-item tool-more"> <a> <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg> </a> <ul class="more-box"> <li class="item"><a class="article-report">文章举报</a></li> </ul> </li> </ul> </div> </div> <div class="person-messagebox"> <div class="left-message"><a href="https://blog.csdn.net/weixin_38808487"> <img src="https://profile.csdnimg.cn/1/0/E/3_weixin_38808487" class="avatar_pic" username="weixin_38808487"> <img src="https://g.csdnimg.cn/static/user-reg-year/2x/3.png" class="user-years"> </a></div> <div class="middle-message"> <div class="title"><span class="tit"><a href="https://blog.csdn.net/weixin_38808487" data-report-click="{"mod":"popu_379"}" target="_blank">至尊小宝宝</a></span> </div> <div class="text"><span>发布了12 篇原创文章</span> · <span>获赞 15</span> · <span>访问量 5万+</span></div> </div> <div class="right-message"> <a href="https://im.csdn.net/im/main.html?userName=weixin_38808487" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信 </a> <a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a> </div> </div> </div>