OpenJPA Webspere 7 Log4j configuration

故事扮演 提交于 2019-12-25 05:23:27

问题


Guys I’m struggling with this one. I am trying to redirect logging from systemout. to a log4j rollingappender file with no success, below is a sample of my 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>

I get the following error as soon as I add this: to the file above. I have tried copying these two files (commons-logging-1.1.jar, log4j-1.2.6.jar) into WEB_INF/lib but didnt fx the problem. Doesnt seem to be much on the web on how to get this working as is. Any ideas ?

Please note that I can not change the classloading policy in Websphere as this would stop my app from working

 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)

回答1:


The openjpa.Log property value of log4j cannot work with the built-in IBM PersistenceProviderImpl because the built-in JPA provider does not have class loader visibility to your application JARs, and there is no class loader configuration option to make that work. The only option is to download OpenJPA yourself and configure it as a third-party persistence provider.



来源:https://stackoverflow.com/questions/10254857/openjpa-webspere-7-log4j-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!