2013-08-02 60 views

回答

1

這已經被保持引用已實例化的MBean上的ClassLoader workarounded:

/** the classLoader to use for future usages */ 
protected final ClassLoader instanciatingClassLoader; 

/** Default constructor */ 
public MyMonitoringBean() { 
      // Keep in reference the classLoader used to instanciate this object 
    this.instanciatingClassLoader = Thread.currentThread().getContextClassLoader(); 
} 

protected ClassLoader getClassLoader() { 
    return instanciatingClassLoader; 
} 

因爲到此MBean調用在一個線程與爲ClassLoader的不是Web應用程序類加載器執行它並不能解決這個票,但對類加載器如特定電話:

getClassLoader().loadClass(className) 

可以通過直接在Web應用程序的類加載器

0

釷可以解決問題已經有些懸而未決,但我現在遇到了同樣的問題。

我觀察到,MBean類的類加載器實際上是MBean所在的Web應用程序的類加載器。

這是由類的類加載器安裝到當前線程您的MBean應該能夠訪問應用程序類:

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());