當我嘗試進行注入時,發現錯誤。 我從official site取得的集成示例。取而代之的"hibernate-entitymanager
「我用"hibernate-core"
然而,隨着"hibernate-entitymanager"
同樣的錯誤PlayFramework 2.5.12 JPAApi注入錯誤
版本
休眠核心 - 5.2.8
戲 - 2.5.12
1) Error injecting constructor, java.lang.NoSuchMethodError: org.hibernate.cfg.AnnotationBinder.bindDefaults(Lorg/hibernate/boot/spi/MetadataBuildingContext;)V
at play.db.jpa.DefaultJPAApi$JPAApiProvider.<init>(DefaultJPAApi.java:54)
at play.db.jpa.DefaultJPAApi$JPAApiProvider.class(DefaultJPAApi.java:35)
while locating play.db.jpa.DefaultJPAApi$JPAApiProvider
while locating play.db.jpa.JPAApi
for field at controllers.api.UsersApi.jpaApi(UsersApi.java:20)
at controllers.api.UsersApi.class(UsersApi.java:20)
while locating controllers.api.UsersApi
for field at controllers.api.ApiFe.usersApi(ApiFe.java:34)
while locating controllers.api.ApiFe
for parameter 27 at router.Routes.<init>(Routes.scala:136)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200)
while locating play.api.http.JavaCompatibleHttpRequestHandler
while locating play.api.http.HttpRequestHandler
for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221)
at play.api.DefaultApplication.class(Application.scala:221)
while locating play.api.DefaultApplication
while locating play.api.Application
for parameter 0 at play.DefaultApplication.<init>(DefaultApplication.java:30)
at play.DefaultApplication.class(DefaultApplication.java:30)
while locating play.DefaultApplication
while locating play.Application
1 error]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:180)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:131)
at scala.Option.map(Option.scala:146)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:131)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:129)
application.conf
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://dev-box-2:3306/localbase?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false"
db.default.user=test
db.default.password=test
db.default.bonecp.logStatements=true
db.default.bonecp.partitionCount=10
db.default.bonecp.maxConnectionsPerPartition=10
db.default.bonecp.minConnectionsPerPartition=1
db.default.bonecp.connectionTimeout=3 seconds
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="defaultPersistenceUnit" >
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
</properties>
</persistence-unit>
</persistence>
build.sbt
libraryDependencies ++= Seq(
javaJdbc,
javaJpa,
cache,
javaWs,
"org.hibernate" % "hibernate-core" % "5.2.8.Final",
...
類
@Singleton
public class UsersApi implements Mappings {
@Inject
JPAApi jpaApi;
...
}
所以玩遊戲是調用一些Hibernate方法,它不會再出現在你正在使用的Hibernate版本中。因此,問他們爲什麼在涉嫌使用JPA API時調用專有方法(您不需要做這樣的事情) –