2017-05-31 46 views
0

我嘗試連接到MySQL使用彈簧啓動,但得到:春天開機1.5.3 __訪問被拒絕的用戶 '' @ 'localhost' 的數據庫 '高考'

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'jee' 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]  
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]  
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 

TpSpringMvc2Application:

package org.opendevup; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
@SpringBootApplication 
public class TpSpringMvc2Application { 

public static void main(String[] args) 
{ 
    SpringApplication.run(TpSpringMvc2Application.class, args); 
} 
} 

application.properties:

spring.datasource.url = jdbc:mysql://localhost:3306/jee 
spring.datasource.data-username = root 
spring.datasource.data-password = 
spring.datasource.driver-class-name = com.mysql.jdbc.Driver 
spring.jpa.show-sql = true 
spring.jpa.hibernate.ddl-auto = create 
spring.jpa.properties.dialect = org.hibernate.dialect.MySQL5Dialect 

的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>net.opendevup</groupId> 
<artifactId>scolarite</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>tp-spring-mvc2</name> 
<description>Demo project for Spring Boot</description> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.3.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>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
    <!-- <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-rest</artifactId> 
    </dependency> --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-thymeleaf</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <scope>runtime</scope> 
    </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> 
+0

你能直接連接到有問題的數據庫嗎? –

+0

是的,我可以連接 –

+0

'spring.jpa.properties.dialect'應該是'spring.jpa.properties.hibernate.dialect'。相反,你也可以使用'spring.jpa.database-platform'。而你的用戶名(和密碼)屬性刪除'data-'部分。 –

回答

1

你的屬性是錯誤的

spring.datasource.data-username = root 
spring.datasource.data-password = 

應該

spring.datasource.username = root 
spring.datasource.password = 

而且方言spring.jpa.properties.dialect應該

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect 

spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect 

對於默認屬性看Spring Boot Reference Guide

+0

現在感謝你的工作,但端口仍然存在一個問題:「配置爲偵聽端口8080的Tomcat連接器無法啓動,端口可能已經在使用中,或者連接器可能配置錯誤。 操作: 驗證連接器的配置,識別並停止在端口8080上偵聽的任何進程,或將此應用程序配置爲偵聽另一個端口。 –

+0

這是無關的。您可能有另一個應用程序在端口8080上運行 –

+0

是的,但是我關閉了它,並且我仍然有相同的問題 –

相關問題