我無法重現錯誤,但讓我糾正你的屬性文件,使彈簧實際上可以讀取你的財產,如果您使用SpringBoot 1.4和更高的。
正如我在post with the same error中發現的那樣,爲了解決這個問題,您試圖增加datasource.max-active
等屬性,對不對?
所以,如果性能不是this default application properties,那麼你必須把它們寫爲
spring.jpa.properties.*= # Additional native properties to set on the JPA provider.
根據這個我建議你改變application.properties
文件到以下幾點:
spring.datasource.url = jdbc:derby:/spring-boot/db;create=true
spring.datasource.username = admin
spring.datasource.password = 1234
# this one is incorrect
# spring.datasource.driver = org.apache.derby.jdbc.EmbeddedDriver
# replace with the one below, otherwise Spring will use his own
# derby driver
spring.datasource.driver-class-name = org.apache.derby.jdbc.EmbeddedDriver
# this one is incorrect as well
# hibernate.dialect = org.hibernate.dialect.DerbyDialect
# use the following way
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.DerbyDialect
spring.jpa.generate-ddl = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.current_session_context_class = org.springframework.orm.hibernate4.SpringSessionContext
# and in order for these guys to work you have to know
# spring.datasource.max-active=100
# spring.datasource.max-idle=8
# spring.datasource.min-idle=8
# your dbcp and look for documentation
# below is the example for Tomcat
spring.datasource.tomcat.max-active=100
spring.datasource.tomcat.max-idle=8
spring.datasource.tomcat.min-idle=8
# make sure you check out the logging
# this is IMPORTANT to see that your
# properties were ACTUALLY picked up
logging.level.org.springframework.web = DEBUG
logging.level.org.hibernate = DEBUG
的預最後3個可能幫助你克服困難的屬性是最難解決的。我從this post here, last answer中挑選了一些知識。它也鏈接到Spring Boot 1.4.1.RELEASE documentation。
最後但並非最不重要的一點,您必須確保您的max-idle
屬性實際上是由Spring選取的。這就是爲什麼我添加了兩個 最後的日誌記錄和調試屬性。
如果仔細查看日誌文件,請檢查它們設置的值。下面是該行的樣子,我
2016-11-17 11:40:27.875 DEBUG 32079 --- [ main] o.hibernate.internal.SessionFactoryImpl : Instantiating session factory with properties: {java.vendor=Oracle Corporation, sun.java.launcher=SUN_STANDARD, catalina.base=/tmp/tomcat.736868414125414090.8080, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, catalina.useNaming=false, hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy, os.name=Linux, sun.boot.class.path=/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/resources.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/rt.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/sunrsasign.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/jsse.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/jce.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/charsets.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/jfr.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/classes, hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext, java.vm.specification.vendor=Oracle Corporation, java.runtime.version=1.8.0_73-b02, user.name=nikiforo, javax.persistence.validation.mode=AUTO, user.language=en, sun.boot.library.path=/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/amd64, PID=32079, java.version=1.8.0_73, user.timezone=Europe/Berlin, sun.arch.data.model=64, java.endorsed.dirs=/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/endorsed, sun.cpu.isalist=, sun.jnu.encoding=UTF-8, file.encoding.pkg=sun.io, file.separator=/, java.specification.name=Java Platform API Specification, java.class.version=52.0, user.country=US, java.home=/usr/users/nikiforo/src/jdk1.8.0_73/jre, java.vm.info=mixed mode, os.version=4.1.20-11-default, hibernate.boot.Cfg[email protected]6abb7b7d, hiberna[email protected]5c7dfc05{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.apache.derby.jdbc.EmbeddedDriver; maxActive=100
這是一個長線的,但你看我max-active
設置。
如果你想在其中看到簡單的Spring-DATA-REST應用我想德比和以下屬性,檢查this mine GitHub project: derby-tomcat-database-error branch
它可以幫助,可能不會,讓我知道,如果我錯了,我會刪除帖子。
通常由於糟糕的事務管理或自己搞亂連接。 –