2017-07-28 115 views
0

我想问我是否需要在使用eclipse和spring boot时指定我的SQL文件的路径?我给出了相同的错误Cannot determine embedded database driver class for database type NONE。我相信所有的设置都是正确的,但问题是我从来没有告诉日食我的数据库在哪里?手动连接mySQL到eclipse/Spring Boot

我有一个属性文件,国家这样的:

spring.jpa.hibernate.ddl-auto=create-drop 
spring.datasource.url=jdbc:mysql://localhost:3306/db_example 
spring.datasource.username=springuser 
spring.datasource.password=ThePassword 
spring.datasource.driverClassName=com.mysql.jdbc.Driver 
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect 

这是为它找到一个db_example方式,它应该以某种方式上网,当我开始我的项目?当我去localhost:3306它也显示一个错误。我在2天内无法解决这个问题,并且对编程来说很新颖,所以请耐心等待!

依赖条件(包括HikariCP)

<?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>io.msela</groupId> 
    <artifactId>course-api-data</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>course-api-data</name> 
    <description>Course API with Spring Data</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.4.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 

    <dependency> 
     <groupId>com.zaxxer</groupId> 
     <artifactId>HikariCP</artifactId> 
    </dependency> 



     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
     </dependency> 

     <!-- <dependency> 
      <groupId>org.apache.derby</groupId> 
      <artifactId>derby</artifactId> 
      <scope>runtime</scope> 
     </dependency> --> 


     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 


</project> 

编辑1

我得到这样的警告也:

2017-07-28 11:05:35.957 WARN 9576 --- [   main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.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). 

EDIT 2 我路上的截图

EDIT 3

移动文件夹之后该错误消息是以下各项:

2017-07-28 11:40:20.348 WARN 10944 --- [   main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver 
+0

正如你的其他问题所述,你需要包含一个'DataSource'实现。你还没有提供...添加像[HikariCP](https://github.com/brettwooldridge/HikariCP)作为依赖项。 –

+0

您是否在Maven/Gradle中添加了mySQL连接器依赖项? – davidxxx

+0

我添加了HiakriCP并添加了mySQL,问题仍然存在! – Asker

回答

2

我没有看到你的application.properties在资源文件夹。相反,您的application.properties处于测试环境中。我不会那样工作。

+0

哦,天啊,所以这是问题!但是现在它显示了一堆错误,而不是之前的错误,称它无法加载驱动程序:/ – Asker

+1

什么是错误信息? –

+0

但我假设你纠正了:spring.datasource.driverClassName = com.mysql.jdbc.Driver正如其他用户指出的那样? –

1

请变更spring.datasource.driverClassName=com.mysql.jdbc.Driverspring.datasource.driver-class-name=com.mysql.jdbc.Driver。 你最终数据库的配置可能是这样的:

spring.jpa.hibernate.ddl-auto=create-drop 
spring.jpa.database-platform = org.hibernate.dialect.MySQLDialect 
spring.datasource.url=jdbc:mysql://localhost:3306/db_example 
spring.datasource.username=springuser 
spring.datasource.password=ThePassword 
spring.datasource.driver-class-name=com.mysql.jdbc.Driver 

也请更新您的pom.xml文件dependencies到这一点,并在Eclipse运行maven update

<dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
+0

我改变了这个,并得到相同的错误:/ – Asker

+0

你能否更新依赖关系并运行配置文件上面的maven更新 –

+0

这样做还是一样的错误。应该添加到我的应用程序?目前,我有这样的: @SpringBootApplication @ComponentScan({ “io.msela”}) @EntityScan( “io.msela.springbootstarter”) @EnableJpaRepositories(basePackageClasses = EmployeeRepository.class) – Asker