Spring Boot和JPA项目抛出JDBC异常

时间:2016-05-17 09:48:38

标签: spring hibernate jpa

我使用Spring Boot和Hibernate作为我的项目,我的数据库是MySql。我使用注释而不是JPA。 当我打电话给Rest api时,我得到的反应如下:

Whitelabel错误页面

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue May 17 11:32:13 CEST 2016
There was an unexpected error (type=Internal Server Error, status=500).
Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.TransactionException: JDBC begin transaction failed:

这是我的application.properties

spring.datasource.url=jdbc:mysql://x.x.x.x:3306/db_myfme?useUnicode=yes&characterEncoding=UTF-8&characterSetResults=UTF-8
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.connection.characterEncoding=utf-8
spring.jpa.properties.hibernate.connection.CharSet=utf-8
spring.jpa.properties.hibernate.connection.useUnicode=true

server.tomcat.uri-encoding=UTF-8


# HTTP encoding (HttpEncodingProperties)
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

spring.mail.host=smtp.gmail.com
spring.mail.username= capfme@gmail.com
spring.mail.password= *******

spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.smtp.socketFactory.port=587
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.ssl.enable = true
spring.mail.properties.mail.smtp.socketFactory.fallback = false

1 个答案:

答案 0 :(得分:0)

spring.datasource.testOnBorrow: true
spring.datasource.validationQuery: SELECT 1
spring.jpa.hibernate.ddl-auto=none