【问题标题】:Spring Boot DatasourceBean error, Macbook, MySQLSpring Boot DatasourceBean错误,Macbook,MySQL
【发布时间】:2016-09-13 00:36:00
【问题描述】:

将应用程序部署到 Tomcat 8 时出现以下错误。我的 macbook 上安装了 MySQL:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate com.catalina.productcarried.dao.impl.ProductCarriedDAOImpl.jdbcTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. 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).
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    ... 26 common frames omitted

这是我的 application.properties 文件:

#Database properties local
spring.datasource.url=jdbc:mysql://localhost:3306/simulator?autoReconnect=true&useSSL=false    
spring.datasource.username=root 
spring.datasource.password=       
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
debug=true

【问题讨论】:

  • 你能粘贴你的 pom 内容吗?
  • com.mysql.jdbc.Driver 在类路径上吗?

标签: mysql spring macos jdbc spring-boot


【解决方案1】:

无法确定数据库类型 NONE 的嵌入式数据库驱动程序类。如果您想要一个嵌入式数据库,请在类路径中放置一个受支持的数据库。如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有配置文件处于活动状态)。

由于某种原因,您的application.properties 未被考虑在内。注意driver-class是不必要的,Spring Boot会从url参数中检测到。

请务必查看以下内容:

  1. mysql 驱动程序在您的依赖项中定义
  2. 您在描述中提供的application.properties文件的内容在one of the supported locations

【讨论】:

    猜你喜欢
    • 2020-10-08
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 2021-06-05
    • 2020-08-25
    • 2015-06-09
    • 2018-10-24
    相关资源
    最近更新 更多