NoSuchProviderException:使用log4j smtp SMTP appender

我使用log4j在发生异常时发送电子邮件。下面是我的log4j属性文件配置。NoSuchProviderException:使用log4j smtp SMTP appender

log4j.rootLogger=WARN, R, email 

log4j.appender.R=org.apache.log4j.ConsoleAppender

log4j.appender.R.layout=org.apache.log4j.PatternLayout

log4j.appender.R.layout.ConversionPattern=%d{HH:mm:ss} %-5p [%c{1}]: %m%n

log4j.appender.email=org.apache.log4j.net.SMTPAppender

log4j.appender.email.BufferSize=10

log4j.appender.email.SMTPHost=myhost.com

[email protected]

[email protected]

log4j.appender.email.Subject=Error

log4j.appender.email.layout=org.apache.log4j.PatternLayout

mine是maven项目我添加了对mail.jar,activation.jar和smtp.jar的依赖关系。但在应用服务器启动本身我得到以下错误:

[ERROR] log4j:ERROR Error occured while sending e-mail notification. 

[ERROR] javax.mail.NoSuchProviderException: smtp

[ERROR] at javax.mail.Session.getService(Session.java:782)

[ERROR] at javax.mail.Session.getTransport(Session.java:708)

[ERROR] at javax.mail.Session.getTransport(Session.java:651)

[ERROR] at javax.mail.Session.getTransport(Session.java:631)

[ERROR] at javax.mail.Session.getTransport(Session.java:686)

[ERROR] at javax.mail.Transport.send0(Transport.java:166)

我失去了什么东西吗?错误的根本原因是什么?是否因为SMTP主机名不正确?还是因为任何缺失/冲突的依赖?

回答:

您不需要smtp.jar和mail.jar - smtp.jar中的所有内容也都在mail.jar中。摆脱smtp.jar,但我怀疑这会解决你的问题。

此外,请确保您的类路径中没有任何其他具有JavaMail类的jar文件,例如javaee.jar或j2ee.jar。

这很可能是某种类路径问题。 JavaMail使用类加载器来查找配置提供程序的配置文件,例如“smtp”。如果类加载器不正确地处理资源查找,则可能会发生此问题。

回答:

您可能想要导出smtp.jar以供您的webapp使用。

回答:

将您的JavaMail升级到1.5.3,其中包含fix的Bug 6668 -skip unusable Store and Transport classes。从错误报告:

In complex class loading situations, it can be possible for there to be multiple copies of the JavaMail classes. 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. In this case, JavaMail should skip over the unusable class and try to load the class from another 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.

您可以从JavaMail reference implementation主页最新快照和官方版本。

以上是 NoSuchProviderException:使用log4j smtp SMTP appender 的全部内容, 来源链接: utcz.com/qa/262129.html

回到顶部