apusic部署应用时报错:Duplicate persistence.xml unit name 'FrameworkPU' found in the application

09:01 提问
junit测试报错,求大神救命,控制台输出如下,
09:04:52,182 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader
- #org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:316)# - Loading XML bean definitions from URL [file:WebRoot/WEB-INF/spring/applicationContext.xml]
09:04:52,877 [main] INFO com.mon.logger.LoggerFactory
- ## - using logger: com.mon.logger.log4j.Log4jLoggerAdapter
09:04:52,883 [main] ERROR com.mon.Version
- #com.mon.Version.checkDuplicate(Version.java:144)# -
[DUBBO] Duplicate class com/alibaba/dubbo/common/Version.class in 3 jar [file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/dubbo-2.8.4.jar!/com/alibaba/dubbo/common/Version.class, file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/original-dubbo-2.8.4.jar!/com/alibaba/dubbo/common/Version.class, file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/dubbo-2.8.4-shaded.jar!/com/alibaba/dubbo/common/Version.class], dubbo version: 2.8.4, current host: 127.0.0.1
09:04:52,884 [main] ERROR com.mon.Version
- #com.mon.Version.checkDuplicate(Version.java:144)# -
[DUBBO] Duplicate class com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.class in 3 jar [file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/dubbo-2.8.4-shaded.jar!/com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.class, file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/original-dubbo-2.8.4.jar!/com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.class, file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/dubbo-2.8.4.jar!/com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.class], dubbo version: 2.8.4, current host: 127.0.0.1
09:04:52,929 [main] INFO org.springframework.context.support.GenericApplicationContext
- #org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:513)# - Refreshing org.springframework.context.support.GenericApplicationContext@cde55ec: startup date [Thu Jul 09 09:04:52 CST 2015]; root of context hierarchy
-09 09:04:53,225 [main] INFO org.springframework.orm.jpa.LocalEntityManagerFactoryBean
- #org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:79)# - Building JPA EntityManagerFactory for persistence unit 'jpa-demo'
[EL Info]:
09:04:54.475--ServerSession()--EclipseLink, version: Eclipse Persistence Services - 2.5.0.vfaac2b
[EL Severe]: ejb:
09:04:56.582--ServerSession()--Exception : org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Error Code: 0
-09 09:04:56,758 [main] ERROR org.springframework.test.context.TestContextManager
- #org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:334)# - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@6fcbba0c] to prepare test instance [test.TestUser@2823a32b]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
按赞数排序
好像是类冲突,有重复的类引起的。一个DubboNamespaceHandler.class文件存在于多jar中。
Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.//这句话是说连接你本机的5432端口被拒绝,然后让你检查主机名和端口是否正确。
我的也报错,。。。求各位大神指导
ERROR com.mon.Version - #com.mon.Version.checkDuplicate(Version.java:144)# - [DUBBO] Duplicate class com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.class in 3 jar [file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/dubbo-2.8.4-shaded.jar!/com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.class, file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/original-dubbo-2.8.4.jar!/com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.class, file:/D:/guyatong/shopworkspace/jpa-demo/WebRoot/WEB-INF/lib/dubbo-2.8.4.jar!/com/alibaba/dubbo/config/spring/schema/DubboNamespaceHandler.class], dubbo version: 2.8.4, current host: 127.0.0.1
从下网上看 [main] ERROR org.springframework.test.context.TestContextManager
/applicationContext.xml文件
110关注|483收录
1056关注|145收录
404关注|937收录
其他相似问题
相关参考资料java - javax.persistence.PersistenceException: No Persistence provider for EntityManager named customerManager - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I am new to JPA & Hibernate. After reading some online materials I now understand what Hibernate is and how it can be used with JPA.
Now, I am trying to run this . I've done everything they mention in this tutorial.
I don't have Oracle DB, only MySQL. So I made some changes to persistence.xml using my understanding of JPA & Hibernate (I don't know if it's correct or not... Seems to me it is.)
Here is my persistence.xml
&persistence xmlns="/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="/xml/ns/persistence /xml/ns/persistence/persistence_1_0.xsd" version="1.0"&
&persistence-unit name="customerManager" transaction-type="RESOURCE_LOCAL"&
&provider&org.hibernate.ejb.HibernatePersistence&/provider&
&class&Customer&/class&
&properties&
&property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/&
&property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/&
&property name="hibernate.show_sql" value="true"/&
&property name="hibernate.connection.username" value="root"/&
&property name="hibernate.connection.password" value="1234"/&
&property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/general"/&
&property name="hibernate.max_fetch_depth" value="3"/&
&/properties&
&/persistence-unit&
&/persistence&
But I don't seem to get the output they describe. It's giving me:
Customer id before creation:null
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence
provider for EntityManager named customerManager
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at CustomerDAO.create(CustomerDAO.java:8)
at CustomerDAO.main(CustomerDAO.java:22)
Any suggestions will be appreciated.
I have made the changes that are asked to done. But, still getting the asme error lines!!!
They didnt mentioned anything about orm.xml in that tutorial. may it be a problem causer!!!
user405398
Your persistence.xml is not valid and the EntityManagerFactory can't get created. It should be:
&persistence xmlns="/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="/xml/ns/persistence /xml/ns/persistence/persistence_1_0.xsd" version="1.0"&
&persistence-unit name="customerManager" transaction-type="RESOURCE_LOCAL"&
&provider&org.hibernate.ejb.HibernatePersistence&/provider&
&class&Customer&/class&
&properties&
&property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/&
&property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/&
&property name="hibernate.show_sql" value="true"/&
&property name="hibernate.connection.username" value="root"/&
&property name="hibernate.connection.password" value="1234"/&
&property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/general"/&
&property name="hibernate.max_fetch_depth" value="3"/&
&/properties&
&/persistence-unit&
&/persistence&
(Note how the &property& elements are closed, they shouldn't be nested)
Update: I went through the tutorial and you will also have to change the Id generation strategy when using MySQL (as MySQL doesn't support sequences). I suggest using the AUTO strategy (defaults to IDENTITY with MySQL). To do so, remove the SequenceGenerator annotation and change the code like this:
@Table(name="TAB_CUSTOMER")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="CUSTOMER_ID", precision=0)
private Long customerId =
This should help.
PS: you should also provide a log4j.properties as suggested.
387k71799980
just for completeness.
there is another situation causing this error: missing META-INF/services/javax.persistence.spi.PersistenceProvider file. for hibernate, it's located in hibernate-entitymanager-XXX.jar, so, if hibernate-entitymanager-XXX.jar is not in your classpath, you will got this error too.
this error message is so misleading, and it costs me hours to get it correct.
5,33831117
I had the same problem today. My persistence.xml was in the wrong location. I had to put it in the following path:
project/src/main/resources/META-INF/persistence.xml
I was facing the same issue. I realised that I was using the Wrong provider class in persistence.xml
For Hibernate it should be
&provider&org.hibernate.ejb.HibernatePersistence&/provider&
And for EclipseLink it should be
&provider&org.eclipse.persistence.jpa.PersistenceProvider&/provider&
A bit too late but I got the same issue and fixed it switching schemalocation into schemaLocation in the persistence.xml file (line 1).
my experience tells me that missing persistence.xml,will generate the same exception too.
i caught the same error msg today when i tried to run a jar package packed by ant.
when i used jar tvf to check the content of the jar file, i realized that "ant" forgot to pack the persistnece.xml for me.
after I manually repacked the jar file ,the error msg disappered.
so i believe maybe you should try simplely putting META-INF under src directory and placing your persistence.xml there.
I have seen this error , for me the issue was there was a space in the absolute path of the persistance.xml , removal of the same helped me.
I was also facing the same issue when I was trying to get JPA entity manager configured in Tomcat 8. First I has an issue with the SystemException class not being found and hence the entityManagerFactory was not being
created. I removed the hibernate entity manager dependency and then my entityManagerFactory was not able to lookup for the persistence provider. After going thru a lot of research and time got to know that hibernate entity manager is must to lookup for some configuration. Then put back the entity manager jar and then added JTA Api as a dependency and it worked fine.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Stack Overflow works best with JavaScript enabledPersistenceUnitInfo (Java EE 6 )
javax.persistence.spi
Interface PersistenceUnitInfo
public interface PersistenceUnitInfo
Interface implemented by the container and used by the
persistence provider when creating an .
Java Persistence 1.0
(&transformer)
&&&&&&&&&&Add a transformer supplied by the provider that will be
called for every new class definition or class redefinition
that gets loaded by the loader returned by the
PersistenceUnitInfo#getClassLoader method.
&&&&&&&&&&Returns whether classes in the root of the persistence unit
that have not been explicitly listed are to be included in the
set of managed classes.
&java.lang.ClassLoader
&&&&&&&&&&Returns ClassLoader that the provider may use to load any
classes, resources, or open URLs.
&java.util.List&java.net.URL&
&&&&&&&&&&Returns a list of URLs for the jar files or exploded jar
file directories that the persistence provider must examine
for managed classes of the persistence unit.
&javax.sql.DataSource
&&&&&&&&&&Returns the JTA-enabled data source to be used by the
persistence provider.
&java.util.List&java.lang.String&
&&&&&&&&&&Returns the list of the names of the classes that the
persistence provider must add to its set of managed
&java.util.List&java.lang.String&
&&&&&&&&&&Returns the list of the names of the mapping files that the
persistence provider must load to determine the mappings for
the entity classes.
&java.lang.ClassLoader
&&&&&&&&&&Return a new instance of a ClassLoader that the provider may
use to temporarily load any classes, resources, or open
&javax.sql.DataSource
&&&&&&&&&&Returns the non-JTA-enabled data source to be used by the
persistence provider for accessing data outside a JTA
transaction.
&java.lang.String
&&&&&&&&&&Returns the fully qualified name of the persistence provider
implementation class.
&java.lang.String
&&&&&&&&&&Returns the name of the persistence unit.
&java.net.URL
&&&&&&&&&&Returns the URL for the jar file or directory that is the
root of the persistence unit.
&java.lang.String
&&&&&&&&&&Returns the schema version of the persistence.xml file.
&java.util.Properties
&&&&&&&&&&Returns a properties object.
&&&&&&&&&&Returns the specification of how the provider must use
a second-level cache for the persistence unit.
&&&&&&&&&&Returns the transaction type of the entity managers created by
the EntityManagerFactory.
&&&&&&&&&&Returns the validation mode to be used by the persistence
provider for the persistence unit.
getPersistenceUnitName
java.lang.String getPersistenceUnitName()
Returns the name of the persistence unit. Corresponds to the
name attribute in the persistence.xml file.
Returns:the name of the persistence unit
getPersistenceProviderClassName
java.lang.String getPersistenceProviderClassName()
Returns the fully qualified name of the persistence provider
implementation class. Corresponds to the provider element in
the persistence.xml file.
Returns:the fully qualified name of the persistence provider
implementation class
getTransactionType
getTransactionType()
Returns the transaction type of the entity managers created by
the EntityManagerFactory. The transaction type corresponds to
the transaction-type attribute in the persistence.xml file.
Returns:transaction type of the entity managers created
by the EntityManagerFactory
getJtaDataSource
javax.sql.DataSource getJtaDataSource()
Returns the JTA-enabled data source to be used by the
persistence provider. The data source corresponds to the
jta-data-source element in the persistence.xml file or is
provided at deployment or by the container.
Returns:the JTA-enabled data source to be used by the
persistence provider
getNonJtaDataSource
javax.sql.DataSource getNonJtaDataSource()
Returns the non-JTA-enabled data source to be used by the
persistence provider for accessing data outside a JTA
transaction. The data source corresponds to the named
non-jta-data-source element in the persistence.xml file or
provided at deployment or by the container.
Returns:the non-JTA-enabled data source to be used by the
persistence provider for accessing data outside a JTA
transaction
getMappingFileNames
java.util.List&java.lang.String& getMappingFileNames()
Returns the list of the names of the mapping files that the
persistence provider must load to determine the mappings for
the entity classes. The mapping files must be in the standard
XML mapping format, be uniquely named and be resource-loadable
from the application classpath.
Each mapping file name
corresponds to a mapping-file element in the
persistence.xml file.
Returns:the list of mapping file names that the persistence
provider must load to determine the mappings for the entity
getJarFileUrls
java.util.List&java.net.URL& getJarFileUrls()
Returns a list of URLs for the jar files or exploded jar
file directories that the persistence provider must examine
for managed classes of the persistence unit. Each URL
corresponds to a jar-file element in the
persistence.xml file. A URL will either be a
file: URL referring to a jar file or referring to a directory
that contains an exploded jar file, or some other URL from
which an InputStream in jar format can be obtained.
Returns:a list of URL objects referring to jar files or
directories
getPersistenceUnitRootUrl
java.net.URL getPersistenceUnitRootUrl()
Returns the URL for the jar file or directory that is the
root of the persistence unit. (If the persistence unit is
rooted in the WEB-INF/classes directory, this will be the
URL of that directory.)
The URL will either be a file: URL referring to a jar file
or referring to a directory that contains an exploded jar
file, or some other URL from which an InputStream in jar
format can be obtained.
Returns:a URL referring to a jar file or directory
getManagedClassNames
java.util.List&java.lang.String& getManagedClassNames()
Returns the list of the names of the classes that the
persistence provider must add to its set of managed
classes. Each name corresponds to a named class element in the
persistence.xml file.
Returns:the list of the names of the classes that the
persistence provider must add to its set of managed
excludeUnlistedClasses
boolean excludeUnlistedClasses()
Returns whether classes in the root of the persistence unit
that have not been explicitly listed are to be included in the
set of managed classes. This value corresponds to the
exclude-unlisted-classes element in the persistence.xml file.
Returns:whether classes in the root of the persistence
unit that have not been explicitly listed are to be
included in the set of managed classes
getSharedCacheMode
getSharedCacheMode()
Returns the specification of how the provider must use
a second-level cache for the persistence unit.
The result of this method corresponds to the shared-cache-mode
element in the persistence.xml file.
Returns:the second-level cache mode that must be used by the
provider for the persistence unitSince:
Java Persistence 2.0
getValidationMode
getValidationMode()
Returns the validation mode to be used by the persistence
provider for the persistence unit.
The validation mode
corresponds to the validation-mode element in the
persistence.xml file.
Returns:the validation mode to be used by the
persistence provider for the persistence unitSince:
Java Persistence 2.0
getProperties
java.util.Properties getProperties()
Returns a properties object. Each property corresponds to a
property element in the persistence.xml file.
Returns:Properties object
getPersistenceXMLSchemaVersion
java.lang.String getPersistenceXMLSchemaVersion()
Returns the schema version of the persistence.xml file.
Returns:persistence.xml schema versionSince:
Java Persistence 2.0
getClassLoader
java.lang.ClassLoader getClassLoader()
Returns ClassLoader that the provider may use to load any
classes, resources, or open URLs.
Returns:ClassLoader that the provider may use to load any
classes, resources, or open URLs
addTransformer
void addTransformer(&transformer)
Add a transformer supplied by the provider that will be
called for every new class definition or class redefinition
that gets loaded by the loader returned by the
PersistenceUnitInfo#getClassLoader method. The transformer
has no effect on the result returned by the
PersistenceUnitInfo#getNewTempClassLoader method.
Classes are only transformed once within the same classloading
scope, regardless of how many persistence units they may be
a part of.
Parameters:transformer - provider-supplied transformer that the
container invokes at class-(re)definition time
getNewTempClassLoader
java.lang.ClassLoader getNewTempClassLoader()
Return a new instance of a ClassLoader that the provider may
use to temporarily load any classes, resources, or open
URLs. The scope and classpath of this loader is exactly the
same as that of the loader returned by PersistenceUnitInfo#getClassLoader. None of the classes loaded
by this class loader will be visible to application
components. The provider may only use this ClassLoader within
the scope of the PersistenceProvider#createContainerEntityManagerFactory call.
Returns:temporary ClassLoader with same visibility as current
Copyright & , Oracle Corporation and/or its affiliates. All Rights Reserved. Use is subject to
Generated on 10-February-
Scripting on this page tracks web page traffic,
but does not change the content in any way.}

我要回帖

更多关于 persistence.xml 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信