Common Logging&Log4j doesn't work properly in OC4J/OAS

In Oracle Appserver, when an EAR file is deployed, which contains common loggin and log4j, it says No Suitable Log Constructor when you try to get a log from log factory.After investigation, it is caused by the parent/child class loader.
 
 
1. In OraAS/j2ee/INST_NAME/config/application.xml, we can see the common logging package is imported.
 
  <import-shared-library name="apache.commons.logging"/>
  </imported-shared-libraries>
 
2. That is to say, the common logging is imported by the system/parent class loader when the appserver instance is started.
 
3. In your webapplication, when you access Log log = LogFactory.getLog(CLASS), then it found the appache common logging has been loaded, so it hand the control to apache commons, apache commons use the auto discovery mechnism to instantialze the LogCatagory in log4j. Unfortunately, commons logging tries to use the system/parent class loader to load log4j. Surely, it fails. Because log4j is under the child/application class loader.
 
4. The solution is that we remove the commons logging shared library from the application. And put common logging and log4j in the application level.Put the following directive into the orion-application.xml under APPL//META-INF.
 
  <imported-shared-libraries>
    <remove-inherited name="apache.commons.logging"/>
  </imported-shared-libraries>

你可能感兴趣的:(oracle,log4j,logging,common,AppServer)