SpringBoot-启动报错(Error starting ApplicationContext)

小鱼儿 2023-06-26 05:37 143阅读 0赞

搭建SpringBoot+mybatis+maven集成项目,在运行启动类main函数的时候控制台报出如下错误,启动失败:

  1. Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2. 2018- 07- 18 16: 57: 29.514 ERROR 17300 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
  3. ***************************
  4. APPLICATION FAILED TO START
  5. ***************************
  6. Description:
  7. Cannot determine embedded database driver class for database type NONE
  8. Action:
  9. 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配置:

  1. <?xml version= "1.0" encoding= "UTF-8"?>
  2. <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion> 4.0.0</modelVersion>
  5. <groupId>SpringBoot</groupId>
  6. <artifactId>SpringBoot</artifactId>
  7. <version> 0.0.1-SNAPSHOT</version>
  8. <packaging>war</packaging>
  9. <name>SpringBoot Maven Webapp</name>
  10. <url>http: //maven.apache.org</url>
  11. <properties>
  12. <project.build.sourceEncoding>UTF- 8</project.build.sourceEncoding>
  13. <maven.compiler.source> 1.7</maven.compiler.source>
  14. <maven.compiler.target> 1.7</maven.compiler.target>
  15. </properties>
  16. <parent>
  17. <groupId>org.springframework.boot</groupId>
  18. <artifactId>spring-boot-starter-parent</artifactId>
  19. <version> 1.5.8.RELEASE</version>
  20. <relativePath></relativePath>
  21. </parent>
  22. <resources>
  23. <resource>
  24. <directory>src/main/java</directory>
  25. <includes>
  26. <include>** /*.properties</include>
  27. <include>**/*.xml</include>
  28. </includes>
  29. <filtering> false</filtering>
  30. </resource>
  31. <resource>
  32. <directory>src/main/resources</directory>
  33. <includes>
  34. <include>** /*.properties</include>
  35. <include>**/*.xml</include>
  36. </includes>
  37. <filtering> false</filtering>
  38. </resource>
  39. </resources>
  40. <dependencies>
  41. <dependency>
  42. <groupId>org.springframework.boot</groupId>
  43. <artifactId>spring-boot-starter</artifactId>
  44. </dependency>
  45. <dependency>
  46. <groupId>org.mybatis.spring.boot</groupId>
  47. <artifactId>mybatis-spring-boot-starter</artifactId>
  48. <version> 1.3.1</version>
  49. </dependency>
  50. <dependency>
  51. <groupId>org.springframework.boot</groupId>
  52. <artifactId>spring-boot-devtools</artifactId>
  53. <optional> true</optional>
  54. </dependency>
  55. <dependency>
  56. <groupId>org.springframework.boot</groupId>
  57. <artifactId>spring-boot-starter-web</artifactId>
  58. </dependency>
  59. <dependency>
  60. <groupId>org.springframework.boot</groupId>
  61. <artifactId>spring-boot-starter-test</artifactId>
  62. <scope>test</scope>
  63. </dependency>
  64. <dependency>
  65. <groupId>org.springframework.boot</groupId>
  66. <artifactId>spring-boot-starter-jdbc</artifactId>
  67. </dependency>
  68. <dependency>
  69. <groupId>org.springframework.boot</groupId>
  70. <artifactId>spring-boot-starter-tomcat</artifactId>
  71. <scope>provided</scope>
  72. </dependency>
  73. <exclusions>
  74. <exclusion>
  75. <artifactId>log4j-over-slf4j</artifactId>
  76. <groupId>org.slf4j</groupId>
  77. </exclusion>
  78. <exclusion>
  79. <groupId>org.springframework.boot</groupId>
  80. <artifactId>spring-boot-starter-tomcat</artifactId>
  81. </exclusion>
  82. </exclusions>
  83. <!-- mysql连接 -->
  84. <dependency>
  85. <groupId>mysql</groupId>
  86. <artifactId>mysql-connector-java</artifactId>
  87. <version> 5.1.42</version>
  88. </dependency>
  89. <!-- mybatis -->
  90. </dependencies>
  91. <build>
  92. <finalName>SpringBoot</finalName>
  93. <pluginManagement><!-- lock down plugins versions to avoid using Maven
  94. defaults (may be moved to parent pom) -->
  95. <plugins>
  96. <plugin>
  97. <groupId>org.springframework.boot</groupId>
  98. <artifactId>spring-boot-maven-plugin</artifactId>
  99. <configuration>
  100. <fork>true</fork>
  101. </configuration>
  102. </plugin>
  103. <plugin>
  104. <artifactId>maven-clean-plugin</artifactId>
  105. <version>3.0.0</version>
  106. </plugin>
  107. <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
  108. <plugin>
  109. <artifactId>maven-resources-plugin</artifactId>
  110. <version>3.0.2</version>
  111. </plugin>
  112. <plugin>
  113. <artifactId>maven-compiler-plugin</artifactId>
  114. <version>3.7.0</version>
  115. </plugin>
  116. <plugin>
  117. <artifactId>maven-surefire-plugin</artifactId>
  118. <version>2.20.1</version>
  119. </plugin>
  120. <plugin>
  121. <artifactId>maven-war-plugin</artifactId>
  122. <version>3.2.0</version>
  123. </plugin>
  124. <plugin>
  125. <artifactId>maven-install-plugin</artifactId>
  126. <version>2.5.2</version>
  127. </plugin>
  128. <plugin>
  129. <artifactId>maven-deploy-plugin</artifactId>
  130. <version>2.8.2</version>
  131. </plugin>
  132. <!--This plugin's configuration is used to store Eclipse m2e settings
  133. only. It has no influence on the Maven build itself. -->
  134. <plugin>
  135. <groupId>org.eclipse.m2e</groupId>
  136. <artifactId>lifecycle-mapping</artifactId>
  137. <version>1.0.0</version>
  138. <configuration>
  139. <lifecycleMappingMetadata>
  140. <pluginExecutions>
  141. <pluginExecution>
  142. <pluginExecutionFilter>
  143. <groupId>
  144. org.apache.maven.plugins
  145. </groupId>
  146. <artifactId>
  147. maven-resources-plugin
  148. </artifactId>
  149. <versionRange>[3.0.2,)</versionRange>
  150. <goals>
  151. <goal>resources</goal>
  152. </goals>
  153. </pluginExecutionFilter>
  154. <action>
  155. <ignore></ignore>
  156. </action>
  157. </pluginExecution>
  158. </pluginExecutions>
  159. </lifecycleMappingMetadata>
  160. </configuration>
  161. </plugin>
  162. </plugins>
  163. </pluginManagement>
  164. </build>
  165. </project>

项目完整路径:

70

很奇怪,我将配置文件全部放在resources文件夹下,官方文档也建议将配置文件放在此文件夹下,但是就是找不到我的数据库配置文件,具体原因暂时还不明白。

解决方法:将数据库配置文件(我的是上图resources文件夹下的application.properties)复制到src/java/main目录下,复制后路径如下图所示:

70 1

其中resources目录下的application.properties文件可以删除了。

上述操作后成功启动项目,问题解决。

发表评论

表情:
评论列表 (有 0 条评论,143人围观)

还没有评论,来说两句吧...

相关阅读