Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 错误:无法实例化类_Java_Log4j_Wso2 - Fatal编程技术网

Java 错误:无法实例化类

Java 错误:无法实例化类,java,log4j,wso2,Java,Log4j,Wso2,我通过WSO2产品使用log4j.properties。我需要实现一个appender来使用SMTPAppender并使用gmail smtp服务器发送电子邮件通知。因此,当我配置log4j并启动ESB WSO2服务器时,管理控制台打印:log4j:ERROR无法实例化类[com.notification.GmailSMTPAppender] 我的实施是: package com.notification; public class GmailSMTPAppender extends SMTP

我通过WSO2产品使用log4j.properties。我需要实现一个appender来使用SMTPAppender并使用gmail smtp服务器发送电子邮件通知。因此,当我配置log4j并启动ESB WSO2服务器时,管理控制台打印:
log4j:ERROR无法实例化类[com.notification.GmailSMTPAppender]

我的实施是:

package com.notification;

public class GmailSMTPAppender extends SMTPAppender {

    protected Session session;

    public GmailSMTPAppender() {
            super();
    }

    /**
     * Create mail session.
     *
     * @return mail session, may not be null.
     */
    protected Session createSession() {
            Properties props = new Properties();
            props.put("mail.smtps.host", getSMTPHost());
            props.put("mail.smtps.auth", "true");

            Authenticator auth = null;
            if (getSMTPPassword() != null && getSMTPUsername() != null) {
                    auth = new Authenticator() {
                            protected PasswordAuthentication getPasswordAuthentication() {
                                    return new PasswordAuthentication(getSMTPUsername(),
                                                    getSMTPPassword());
                            }
                    };
            }
            session = Session.getInstance(props, auth);
            if (getSMTPProtocol() != null) {
                    session.setProtocolForAddress("rfc822", getSMTPProtocol());
            }
            if (getSMTPDebug()) {
                    session.setDebug(getSMTPDebug());
            }
            return session;
    }

    /**
     * Send the contents of the cyclic buffer as an e-mail message.
     */
    protected void sendBuffer() {
            try {
                    MimeBodyPart part = new MimeBodyPart();

                    StringBuffer sbuf = new StringBuffer();
                    String t = layout.getHeader();
                    if (t != null)
                            sbuf.append(t);
                    int len = cb.length();
                    for (int i = 0; i < len; i++) {
                            LoggingEvent event = cb.get();
                            sbuf.append(layout.format(event));
                            if (layout.ignoresThrowable()) {
                                    String[] s = event.getThrowableStrRep();
                                    if (s != null) {
                                            for (int j = 0; j < s.length; j++) {
                                                    sbuf.append(s[j]);
                                                    sbuf.append(Layout.LINE_SEP);
                                            }
                                    }
                            }
                    }
                    t = layout.getFooter();
                    if (t != null)
                            sbuf.append(t);
                    part.setContent(sbuf.toString(), layout.getContentType());

                    Multipart mp = new MimeMultipart();
                    mp.addBodyPart(part);
                    msg.setContent(mp);

                    msg.setSentDate(new Date());
                    send(msg);
            } catch (Exception e) {
                    LogLog.error("Error occured while sending e-mail notification.", e);
            }
    }

    /**
     * Pulled email send stuff i.e. Transport.send()/Transport.sendMessage(). So
     * that on required this logic can be enhanced.
     *
     * @param msg
     *            Email Message
     * @throws MessagingException
     */
    protected void send(Message msg) throws MessagingException {
            SMTPTransport t = (SMTPTransport) session.getTransport("smtps");
            try {
                    t.connect(getSMTPHost(), getSMTPUsername(), getSMTPPassword());
                    t.sendMessage(msg, msg.getAllRecipients());
            } finally {
                    System.out.println("Response: " + t.getLastServerResponse());
                    t.close();
            }
    }

}
package.com.notification;
公共类GmailSMTPAppender扩展了SMTPAppender{
受保护会话;
公共Gmail附件(){
超级();
}
/**
*创建邮件会话。
*
*@返回邮件会话,不能为空。
*/
受保护的会话createSession(){
Properties props=新属性();
put(“mail.smtps.host”,getSMTPHost());
props.put(“mail.smtps.auth”、“true”);
验证器auth=null;
如果(getSMTPPassword()!=null&&getSMTPUsername()!=null){
auth=新身份验证器(){
受保护的密码身份验证getPasswordAuthentication(){
返回新密码身份验证(getSMTPUsername(),
getSMTPPassword());
}
};
}
session=session.getInstance(props,auth);
如果(getSMTPProtocol()!=null){
setProtocolForAddress(“rfc822”,getSMTPProtocol());
}
if(getSMTPDebug()){
setDebug(getSMTPDebug());
}
返回会议;
}
/**
*将循环缓冲区的内容作为电子邮件发送。
*/
受保护的void sendBuffer(){
试一试{
MimeBodyPart=新的MimeBodyPart();
StringBuffer sbuf=新的StringBuffer();
字符串t=layout.getHeader();
如果(t!=null)
sbuf.append(t);
int len=cb.length();
对于(int i=0;i

如何在log4j.properties配置中实例化此appender???

是否需要通过编程方式添加appender?
检查以下内容

粘贴完整堆栈跟踪可能会有帮助您将jar放在何处?在使用WSO2_ESBDid的库的存储库中,您找到了解决此问题的方法吗?我遇到了同样的问题。