当我在eclipse IDE上运行我的应用程序时,一切正常,但是当我打包它时,我得到了异常。然后,如果我再次使用jackson的依赖关系将其打包在我的pom中,我没有任何问题,但我想知道为什么当我在IDE上运行它时,即使没有jackson的依赖项,也不会抛出任何异常。依赖树是:
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.0.2.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | +- org.hibernate:hibernate-core:jar:5.0.2.Final:compile
[INFO] | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | \- org.jboss:jandex:jar:1.2.2.Final:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | +- org.hibernate.common:hibernate-commons-annotations:jar:5.0.0.Final:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.4.1:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.4.1:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.13:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.13:compile
[INFO] +- javax.mail:mail:jar:1.4.1:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] \- postgresql:postgresql:jar:9.1-901.jdbc4:compile
堆栈跟踪:
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Exception in thread "main" javax.persistence.PersistenceException: Unable to build entity manager factory
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:66)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at br.com.testejpa.view.Main.main(Main.java:15)
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.apache.logging.log4j.core.appender.db.jpa.converter.ContextMapJsonAttributeConverter]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:232)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.applyScanResultsToManagedResources(ScanningCoordinator.java:235)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:81)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:98)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:194)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
... 3 more
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/type/TypeReference
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:226)
... 12 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.type.TypeReference
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
答案 0 :(得分:0)
您使用JSON布局还是JSON配置?
每个log4j功能的依赖关系在此处记录: http://logging.apache.org/log4j/2.x/runtime-dependencies.html
答案 1 :(得分:0)
试试这个:
下面
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
添加:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
<scope>runtime</scope>
</dependency>