用JAVA发送邮件时,由于要用到TLS,就要注册ssl.SocketFactory.provider,但是居然发生classnotfound异常。代码如下:
java.security.Security.setProperty("ssl.SocketFactory.provider",
"com.hollycrm.service.ticket.util.DNESSLSocketFactory");
异常信息:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS
javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.net.SocketException: java.lang.ClassNotFoundException: com.hollycrm.service.ticket.util.DNESSLSocketFactory
奇怪的是,这个类明明存在,路径也没错:
package com.hollycrm.service.ticket.util;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import javax.net.SocketFactory;
import javax.net.ssl.*;
public class DNESSLSocketFactory extends SSLSocketFactory {
class文件也有DNESSLSocketFactory.class
不知道大家有没有遇到过类似的情况,请大家帮忙分析一下,小弟万分感谢!
Java 邮件 找不到类
------解决方案--------------------
import java.net.URLClassLoader;
import java.util.Arrays;
public class ClasspathDumper
{
public static void main(String... args)
{
dumpClasspath(ClasspathDumper.class.getClassLoader());
}
public static void dumpClasspath(ClassLoader loader)
{
System.out.println("Classloader " + loader + ":");
if (loader instanceof URLClassLoader)
{
URLClassLoader ucl = (URLClassLoader)loader;
System.out.println("\t" + Arrays.toString(ucl.getURLs()));