简体   繁体   English

当类加载器设置为父级时,log4j日志在Websphere中不起作用

[英]log4j log not working in Websphere when Class loader setting is parent first

I am having two problems. 我有两个问题。 In my application we are using custom email functionality with javax.mail api. 在我的应用程序中,我们将自定义电子邮件功能与javax.mail api结合使用。 Mails are going fine with out any error when the class loader setting is kept as Parent First but custom logs are not getting generated with that class loader setting. 当类加载器设置保留为Parent First时,邮件运行良好,没有任何错误,但是使用该类加载器设置未生成自定义日志。

When I update the class loader to Parent Last then logs are getting generated but the custom email functionality is not working, its getting freezed at message.saveChanges(); 当我将类加载器更新为Parent Last时,将生成日志,但是自定义电子邮件功能不起作用,其冻结在message.saveChanges();中。 line and server is throwing time out error. 线路和服务器抛出超时错误。

I have mail.jar & log4j.jar included in the WEB-INF/lib of the application and the log4j.properties file is present in the classes folder 我在应用程序的WEB-INF / lib中包含mail.jar和log4j.jar,并且在类文件夹中存在log4j.properties文件

Could any one please let me know what is causing this issue and Is there a way to make both logging and email functionality work with a single class loader setting. 任何人都可以让我知道导致此问题的原因吗,有没有一种方法可以使日志记录和电子邮件功能同时使用单个类加载器设置。

Thanks. 谢谢。

This most likely is caused because Log4J doesn't load the configuration file ( log4j.xml or log4j.properties ) that you think it does. 这很可能是由于Log4J没有加载您认为应该加载的配置文件( log4j.xmllog4j.properties )引起的。

Add the log4j.debug=true system property, restart the server and watch the logs. 添加log4j.debug=true系统属性,重新启动服务器并查看日志。 The logs (in SystemOut.log or SystemErr.log ) will tell you exactly which configuration file was loaded. 日志(位于SystemOut.logSystemErr.log )将准确告诉您加载了哪个配置文件。

Your version of JavaMail must be fairly old since you are using the 'mail.jar'. 由于您使用的是'mail.jar',因此您的JavaMail版本必须相当旧。

Upgrade the JavaMail included with websphere to 1.5.3 which contains the fix for Bug 6668 -skip unusable Store and Transport classes . 升级了JavaMail包括在WebSphere 1.5.3到含有修复Bug的6668 -skip无法使用存储和运输类 From the bug report: 从错误报告:

In complex class loading situations, it can be possible for there to be multiple copies of the JavaMail classes. 在复杂的类加载情况下,可能有多个JavaMail类副本。 A Store or Transport defined by one copy may be loaded by another copy, but it won't be usable because they're in different ClassLoaders. 由一个副本定义的存储或传输可能会由另一个副本加载,但由于它们位于不同的ClassLoader中而无法使用。 In this case, JavaMail should skip over the unusable class and try to load the class from another ClassLoader. 在这种情况下,JavaMail应该跳过不可用的类,并尝试从另一个ClassLoader加载该类。

This can happen, for example, in GlassFish if the application includes the JavaMail classes, the application class loader is configured to prefer application classes over system classes, and the app server itself tries to use JavaMail when running in the context of the application. 例如,在GlassFish中,如果应用程序包含JavaMail类,并且应用程序类加载器配置为比系统类更喜欢应用程序类,并且应用程序服务器本身在应用程序上下文中运行时尝试使用JavaMail,则可能会发生这种情况。

You need to then remove that old version of JavaMail from your WEB-INF/lib and if need be, place JavaMail 1.5.3 in WEB-INF/lib too. 然后,您需要从WEB-INF / lib中删除旧版本的JavaMail,如果需要,也可以将JavaMail 1.5.3放在WEB-INF / lib中。 I've tested this fix for GlassFish so I'm assuming lots of other appservers suffer this same issue. 我已经为GlassFish测试了此修复程序,因此我假设许多其他应用服务器也遇到了同样的问题。

You can download the latest snapshot and official releases from the JavaMail reference implementation home page. 您可以从JavaMail参考实施主页下载最新的快照和官方发行版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM