EclipseLink:如何为eclipselink 2.7.0

时间:2017-03-31 18:00:18

标签: java jpa logging osgi eclipselink

Bundle org.eclipse.persistence.extension_2.7.0.qualifier.jar(我安装到osgi框架)包含类org.eclipse.persistence.logging.slf4j.SLF4JLogger。在我的持久性文件中,我有

<property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.slf4j.SLF4JLogger"/>

但是我得到了

Exception Description: ClassNotFound: [org.eclipse.persistence.logging.slf4j.SLF4JLogger] specified in [eclipselink.logging.logger] property.
Internal Exception: java.lang.ClassNotFoundException: org.eclipse.persistence.logging.slf4j.SLF4JLogger not found by org.eclipse.persistence.jpa [11]
    at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:231)
    ... 36 more
Caused by: Exception [EclipseLink-28006] (Eclipse Persistence Services - 2.7.0.qualifier): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: ClassNotFound: [org.eclipse.persistence.logging.slf4j.SLF4JLogger] specified in [eclipselink.logging.logger] property.
Internal Exception: java.lang.ClassNotFoundException: org.eclipse.persistence.logging.slf4j.SLF4JLogger not found by org.eclipse.persistence.jpa [11]
    at org.eclipse.persistence.exceptions.EntityManagerSetupException.classNotFoundForProperty(EntityManagerSetupException.java:135)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.findClassForPropertyInternal(EntityManagerSetupImpl.java:1341)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.findClassForProperty(EntityManagerSetupImpl.java:1327)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.updateLoggers(EntityManagerSetupImpl.java:1202)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1752)
    ... 34 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.persistence.logging.slf4j.SLF4JLogger not found by org.eclipse.persistence.jpa [11]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(PrivilegedAccessHelper.java:165)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.findClass(EntityManagerSetupImpl.java:1319)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.findClassForPropertyInternal(EntityManagerSetupImpl.java:1337)
    ... 37 more

我已检查过包org.eclipse.persistence.extension_2.7.0.qualifier.jar没有导出包org.eclipse.persistence.logging.slf4j那么,是否有人可以解释如何让eclipselink登录slf4j?

2 个答案:

答案 0 :(得分:0)

确保包含“ org.eclipse.persistence.extension” jar,它应该可以正常工作。我使用的Maven坐标是

  <dependency>
     <groupId>org.eclipse.persistence</groupId>
     <artifactId>org.eclipse.persistence.extension</artifactId>
     <version>2.7.2</version>
     <scope>runtime</scope>
  </dependency>

答案 1 :(得分:-1)

由于 org.eclipse.persistence.logging.slf4j.SLF4JLogger 不是由提供包导出的,因此您必须通过创建一个扩展 org.eclipse.persistence.logging.AbstractSessionLog 的记录器类在代码中对其进行调整,并覆盖/实现一些方法,就像在原始 { 中所做的那样{1}}

基本上它只是来自 EclipseLink 的原始记录器的副本。

现在,在创建 EntityManagerFactory 时传递给 PersistenceProvider 的 JPA 属性映射中,添加 EclipseLink 日志记录类别和级别。

org.eclipse.persistence.logging.slf4j.SLF4JLogger

还要确保将以下具有您选择的级别的记录器添加到您的日志记录后端。

例如,对于 Logback,声明将如下所示。

Map<String, Object> properties = new HashMap<>();
// Add the necessary logging category and level as per your requirement.
properties.put("eclipselink.logging.level.connection", "FINE");
properties.put("eclipselink.logging.level.jpa", "FINER");
properties.put("eclipselink.logging.level.sql", "FINEST");
// and so on for other categories which can be found in
// org.eclipse.persistence.logging.SessionLog

// Now put your logger class in persistence properties map so that EclipseLink use your logger instance.
properties.put("eclipselink.logging.logger", <your logger>.class.getName());

我正在添加一个来自开源项目的 GitHub link,该项目改编了原始 <logger name="eclipselink.logging" level="DEBUG" additivity="false"> <appender-ref ref="ROLLING_FILE"/> </logger> 的源代码

希望这会有所帮助。