0

伙计们,我正在努力解决这个问题。我正在尝试从 systemout 重定向日志记录。到一个没有成功的 log4j rollingappender 文件,下面是我的 persistent.xml 的示例

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    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_1_0.xsd" version="1.0">
    <persistence-unit name="R_TEST" transaction-type="RESOURCE_LOCAL">
        <provider>
    com.ibm.websphere.persistence.PersistenceProviderImpl
        </provider>
       <non-jta-data-source>jdbc/TESTDB</non-jta-data-source>
         <class>com.ra.WSProcess</class>
    <property name="openjpa.jdbc.Schema" value="TEST" />
            <property name="openjpa.Log" value="log4j"/>    
        </properties>
    </persistence-unit>

将其添加到上面的文件后,我立即收到以下错误。我尝试将这两个文件(commons-logging-1.1.jar、log4j-1.2.6.jar)复制到 WEB_INF/lib 中,但没有解决问题。网络上似乎没有太多关于如何使其按原样工作的内容。有任何想法吗 ?

请注意,我无法更改 Websphere 中的类加载策略,因为这会阻止我的应用程序工作

 java.lang.NoClassDefFoundError
    java.lang.NoClassDefFoundError: org.apache.log4j.Priority
        at java.lang.J9VMInternals.verifyImpl(Native Method)
        at java.lang.J9VMInternals.verify(J9VMInternals.java:72)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:134)
        at org.apache.openjpa.lib.log.Log4JLogFactory.newLogAdapter(Log4JLogFactory.java:33)
        at org.apache.openjpa.lib.log.LogFactoryAdapter.getLog(LogFactoryAdapter.java:40)
        at org.apache.openjpa.lib.conf.ConfigurationImpl.getLog(ConfigurationImpl.java:223)
        at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getConfigurationLog(OpenJPAConfigurationImpl.java:1445)
        at org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationProviderImpl.setInto(PersistenceProductDerivation.java:479)
        at com.ibm.ws.persistence.jdbc.kernel.WsJpaJDBCBrokerFactory.newInstance(WsJpaJDBCBrokerFactory.java:121)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:599)
        at org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:124)
        at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:62)
        at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:102)
        at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:81)
        at com.ibm.websphere.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:71)
        at com.ibm.websphere.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:41)
        at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:109)
        at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:53)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
        at com.ra.WSProcess.EntityManagerHelper.<clinit>(EntityManagerHelper.java:20)
        at java.lang.J9VMInternals.initializeImpl(Native Method)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
        at com.ra.WSProcess.process(WSProcess.java:129)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:599)
        at org.apache.axis2.jaxws.server.dispatcher.JavaDispatcher.invokeTargetOperation(JavaDispatcher.java:76)
        at org.apache.axis2.jaxws.server.dispatcher.JavaBeanDispatcher.invoke(JavaBeanDispatcher.java:96)
        at org.apache.axis2.jaxws.server.EndpointController.invoke(EndpointController.java:108)
        at org.apache.axis2.jaxws.server.JAXWSMessageReceiver.receive(JAXWSMessageReceiver.java:159)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:182)
        at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
        at com.ibm.ws.websvcs.transport.http.WASAxis2Servlet.doPost(WASAxis2Servlet.java:1330)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1443)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:790)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
        at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175)
        at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:859)
        at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557)
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
        at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
        at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
        at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
        at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
        at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
        at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:202)
        at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:766)
        at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896)
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)
    Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
        at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:402)
        at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:347)
4

1 回答 1

1

openjpa.Log属性值log4j不能与内置 IBM PersistenceProviderImpl 一起使用,因为内置 JPA 提供程序对您的应用程序 JAR 没有类加载器可见性,并且没有类加载器配置选项可以使其工作。唯一的选择是自己下载 OpenJPA 并将其配置为第三方持久性提供程序

于 2012-04-21T13:45:58.933 回答