原因 此錯誤在javax.mail.Session.java中的getDefaultInstance方法中引發。根據此源代碼,當默認會話對象已經初始化,但驗證器實例被更新或更改,或者默認會話對象的類加載器與參數驗證器不同時,會發生此錯誤。可能使用java郵件的默認會話實例的java源代碼被重新編譯並重新加載,或者重複的javamail類庫被包含到環境的Classpath中。 它給了妥善的解決辦法
javax.mail.Session.java file
public static synchronized Session getDefaultInstance(Properties props,
Authenticator authenticator) {
if (defaultSession == null)
defaultSession = new Session(props, authenticator);
else {
// have to check whether caller is allowed to see default session
if (defaultSession.authenticator == authenticator)
; // either same object or both null, either way OK
else if (defaultSession.authenticator != null &&
authenticator != null &&
defaultSession.authenticator.getClass().getClassLoader() ==
authenticator.getClass().getClassLoader())
; // both objects came from the same class loader, OK
else
// anything else is not allowed
throw new SecurityException("Access to default session denied");
}
return defaultSession;
}
http://download.oracle.com/javaee/6/api/javax/mail/Session.html#getInstance(java.util.Properties)此文檔可以幫助你理解差異 – 2010-11-15 12:24:39
@ org.life .java:我找不到任何區別?你能指點我一些特定的句子/段嗎? – Gnanam 2010-11-15 12:59:30
'getInstance()':獲取一個新的Session對象。 ,'getDefaultInstance()':獲取默認的Session對象。如果尚未設置默認值,則會創建並安裝一個新的Session對象作爲默認值。 – 2010-11-15 13:11:46