2 a502817870 a502817870 于 2014.07.15 18:04 提问

play-spring-jpa 连接数据库出错

persistence.xml中配置

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">

<persistence-unit name="default" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>DefaultDS</jta-data-source>  
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>

    </properties>
</persistence-unit>

报错内容

play.api.UnexpectedException: Unexpected exception[UnsatisfiedDependencyExceptio
n: Error creating bean with name 'application' defined in file [D:\play-spring-d
ata-jpa\target\scala-2.10\classes\controllers\Application.class]: Unsatisfied de
pendency expressed through constructor argument with index 0 of type [models.Per
sonRepository]: : Error creating bean with name 'personRepository': Cannot creat
e inner bean '(inner bean)' of type [org.springframework.orm.jpa.SharedEntityMan
agerCreator] while setting bean property 'entityManager'; nested exception is or
g.springframework.beans.factory.BeanCreationException: Error creating bean with
name '(inner bean)#1': Cannot resolve reference to bean 'entityManagerFactory' w
hile setting constructor argument; nested exception is org.springframework.beans
.factory.BeanCreationException: Error creating bean with name 'entityManagerFact
ory' defined in class Global$SpringDataJpaConfiguration: Instantiation of bean f
ailed; nested exception is org.springframework.beans.factory.BeanDefinitionStore
Exception: Factory method [public javax.persistence.EntityManagerFactory Global$
SpringDataJpaConfiguration.entityManagerFactory()] threw exception; nested excep
tion is javax.persistence.PersistenceException: [PersistenceUnit: default] Unabl
e to build EntityManagerFactory; nested exception is org.springframework.beans.f
actory.BeanCreationException: Error creating bean with name 'personRepository':
Cannot create inner bean '(inner bean)' of type [org.springframework.orm.jpa.Sha
redEntityManagerCreator] while setting bean property 'entityManager'; nested exc
eption is org.springframework.beans.factory.BeanCreationException: Error creatin
g bean with name '(inner bean)#1': Cannot resolve reference to bean 'entityManag
erFactory' while setting constructor argument; nested exception is org.springfra
mework.beans.factory.BeanCreationException: Error creating bean with name 'entit
yManagerFactory' defined in class Global$SpringDataJpaConfiguration: Instantiati
on of bean failed; nested exception is org.springframework.beans.factory.BeanDef
initionStoreException: Factory method [public javax.persistence.EntityManagerFac
tory Global$SpringDataJpaConfiguration.entityManagerFactory()] threw exception;
nested exception is javax.persistence.PersistenceException: [PersistenceUnit: de
fault] Unable to build EntityManagerFactory]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anon
fun$1.apply(ApplicationProvider.scala:148) ~[play_2.10.jar:2.2.3]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anon
fun$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.3]
at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply
(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.3]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply
(ApplicationProvider.scala:110) ~[play_2.10.jar:2.2.3]
at scala.util.Success.flatMap(Try.scala:200) ~[scala-library.jar:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Err
or creating bean with name 'application' defined in file [D:\play-spring-data-jp
a\target\scala-2.10\classes\controllers\Application.class]: Unsatisfied dependen
cy expressed through constructor argument with index 0 of type [models.PersonRep
ository]: : Error creating bean with name 'personRepository': Cannot create inne
r bean '(inner bean)' of type [org.springframework.orm.jpa.SharedEntityManagerCr
eator] while setting bean property 'entityManager'; nested exception is org.spri
ngframework.beans.factory.BeanCreationException: Error creating bean with name '
(inner bean)#1': Cannot resolve reference to bean 'entityManagerFactory' while s
etting constructor argument; nested exception is org.springframework.beans.facto
ry.BeanCreationException: Error creating bean with name 'entityManagerFactory' d
efined in class Global$SpringDataJpaConfiguration: Instantiation of bean failed;
nested exception is org.springframework.beans.factory.BeanDefinitionStoreExcept
ion: Factory method [public javax.persistence.EntityManagerFactory Global$Spring
DataJpaConfiguration.entityManagerFactory()] threw exception; nested exception i
s javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to b
uild EntityManagerFactory; nested exception is org.springframework.beans.factory
.BeanCreationException: Error creating bean with name 'personRepository': Cannot
create inner bean '(inner bean)' of type [org.springframework.orm.jpa.SharedEnt
ityManagerCreator] while setting bean property 'entityManager'; nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating bean
with name '(inner bean)#1': Cannot resolve reference to bean 'entityManagerFact
ory' while setting constructor argument; nested exception is org.springframework
.beans.factory.BeanCreationException: Error creating bean with name 'entityManag
erFactory' defined in class Global$SpringDataJpaConfiguration: Instantiation of
bean failed; nested exception is org.springframework.beans.factory.BeanDefinitio
nStoreException: Factory method [public javax.persistence.EntityManagerFactory G
lobal$SpringDataJpaConfiguration.entityManagerFactory()] threw exception; nested
exception is javax.persistence.PersistenceException: [PersistenceUnit: default]
Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.ConstructorResolver.createA
rgumentArray(ConstructorResolver.java:730) ~[spring-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowir
eConstructor(ConstructorResolver.java:196) ~[spring-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1045) ~[spri
ng-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949) ~[spring
-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) ~[spring-beans
.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans.j
ar:3.2.3.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'personRepository': Cannot create inner bean '(inner bean)' of
type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bea
n property 'entityManager'; nested exception is org.springframework.beans.factor
y.BeanCreationException: Error creating bean with name '(inner bean)#1': Cannot
resolve reference to bean 'entityManagerFactory' while setting constructor argum
ent; nested exception is org.springframework.beans.factory.BeanCreationException
: Error creating bean with name 'entityManagerFactory' defined in class Global$S
pringDataJpaConfiguration: Instantiation of bean failed; nested exception is org
.springframework.beans.factory.BeanDefinitionStoreException: Factory method [pub
lic javax.persistence.EntityManagerFactory Global$SpringDataJpaConfiguration.ent
ityManagerFactory()] threw exception; nested exception is javax.persistence.Pers
istenceException: [PersistenceUnit: default] Unable to build EntityManagerFactor
y
at org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveInnerBean(BeanDefinitionValueResolver.java:282) ~[spring-beans.jar:3.2.3
.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126) ~[spring-beans.ja
r:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387) ~[spri
ng-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:1128) ~[spring-bean
s.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans
.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans.j
ar:3.2.3.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name '(inner bean)#1': Cannot resolve reference to bean 'entityMana
gerFactory' while setting constructor argument; nested exception is org.springfr
amework.beans.factory.BeanCreationException: Error creating bean with name 'enti
tyManagerFactory' defined in class Global$SpringDataJpaConfiguration: Instantiat
ion of bean failed; nested exception is org.springframework.beans.factory.BeanDe
finitionStoreException: Factory method [public javax.persistence.EntityManagerFa
ctory Global$SpringDataJpaConfiguration.entityManagerFactory()] threw exception;
nested exception is javax.persistence.PersistenceException: [PersistenceUnit: d
efault] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveReference(BeanDefinitionValueResolver.java:329) ~[spring-beans.jar:3.2.3
.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) ~[spring-beans.ja
r:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolve
ConstructorArguments(ConstructorResolver.java:615) ~[spring-beans.jar:3.2.3.RELE
ASE]
at org.springframework.beans.factory.support.ConstructorResolver.instant
iateUsingFactoryMethod(ConstructorResolver.java:441) ~[spring-beans.jar:3.2.3.RE
LEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:10
25) ~[spring-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:921) ~[spring
-beans.jar:3.2.3.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'entityManagerFactory' defined in class Global$SpringDataJpaCo
nfiguration: Instantiation of bean failed; nested exception is org.springframewo
rk.beans.factory.BeanDefinitionStoreException: Factory method [public javax.pers
istence.EntityManagerFactory Global$SpringDataJpaConfiguration.entityManagerFact
ory()] threw exception; nested exception is javax.persistence.PersistenceExcepti
on: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.ConstructorResolver.instant
iateUsingFactoryMethod(ConstructorResolver.java:581) ~[spring-beans.jar:3.2.3.RE
LEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:10
25) ~[spring-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:921) ~[spring
-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) ~[spring-beans
.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans.j
ar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:295) ~[spring-beans.jar:3.2.3.RELEASE]
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Facto
ry method [public javax.persistence.EntityManagerFactory Global$SpringDataJpaCon
figuration.entityManagerFactory()] threw exception; nested exception is javax.pe
rsistence.PersistenceException: [PersistenceUnit: default] Unable to build Entit
yManagerFactory
at org.springframework.beans.factory.support.SimpleInstantiationStrategy
.instantiate(SimpleInstantiationStrategy.java:181) ~[spring-beans.jar:3.2.3.RELE
ASE]
at org.springframework.beans.factory.support.ConstructorResolver.instant
iateUsingFactoryMethod(ConstructorResolver.java:570) ~[spring-beans.jar:3.2.3.RE
LEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:10
25) ~[spring-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:921) ~[spring
-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) ~[spring-beans
.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans.j
ar:3.2.3.RELEASE]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Un
able to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Con
figuration.java:915) ~[hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Final]
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(Hib
ernatePersistence.java:57) ~[hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Fin
al]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:63) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:47) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
at Global$SpringDataJpaConfiguration.entityManagerFactory(Global.java:76
) ~[na:na]
at Global$SpringDataJpaConfiguration$$EnhancerByCGLIB$$715a97cd.CGLIB$en
tityManagerFactory$0() ~[na:na]
Caused by: org.hibernate.HibernateException: The chosen transaction strategy req
uires access to the JTA TransactionManager
at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:
390) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1872) ~[hibernate-core-3.6.10.Final.jar:3.6.10.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Con
figuration.java:906) ~[hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Final]
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(Hib
ernatePersistence.java:57) ~[hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Fin
al]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:63) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:47) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!