簡體   English   中英

無法通過JConsole使MXBean連接到數據庫

[英]Can't make MXBean to connect to database through JConsole

我只是希望有人看到並解決了這個問題。 我有一個MBean和一個MXBean類。 兩者都使用相同的服務類來通過DAO類訪問數據庫。 我使用spring 3.0來初始化這些類並使用JConsole來測試這些bean。 這兩個bean都有相同的方法名稱來訪問它們的服務類,比如說methodA()。 但是當連接到oracle數據庫時,只有MBean類返回數據。 另一個MXBean類會產生一些錯誤。


這是錯誤


EL Severe]: 2012-05-18 10:37:54.134--ServerSession(1992289)--Thread(Thread[RMI TCP Connection(6)-10.208.138.241,5,RMI Runtime])--java.lang.IllegalArgumentException: interface oracle.ucp.jdbc.LabelableConnection is not visible from class loader
    at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
    at oracle.ucp.jdbc.proxy.ConnectionProxyFactory.createConnectionProxy(ConnectionProxyFactory.java:78)
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:658)
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:613)
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:607)
    at org.springframework.jdbc.datasource.DelegatingDataSource.getConnection(DelegatingDataSource.java:83)
    at com.trgr.cobalt.dataorch.datasource.BaseDODataSource.getRawConnection(BaseDODataSource.java:76)
    at com.trgr.cobalt.dataorch.datasource.BaseDODataSource.getConnection(BaseDODataSource.java:46)
    at com.trgr.cobalt.dataorch.datasource.BaseDODataSource.getConnection(BaseDODataSource.java:35)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:126)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:327)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:291)
    at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:415)
    at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:155)
    at org.eclipse.persistence.sessions.server.ExternalConnectionPool.startUp(ExternalConnectionPool.java:118)
    at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:495)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:627)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:230)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:389)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)



這是我的彈簧配置

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"
    lazy-init="false">
    <property name="namingStrategy" ref="namingStrategy"></property>
    <property name="assembler" ref="assembler"></property>
    <property name="autodetect" value="true" />
</bean>

<bean id="attributeSource"
    class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
<bean id="assembler"
    class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
    <property name="attributeSource" ref="attributeSource" />
</bean>
<bean id="namingStrategy"
    class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
    <property name="attributeSource" ref="attributeSource" />
</bean>


<bean class="myclass.jmx.DocumentMBean"
    p:schedulerService-ref="documentService" />

<bean class="myclass.jmx.DocumentMXBean"
    p:schedulerService-ref="documentService" />

DocumentMBean是一個常規MBean。 DocumentMXBean是一個MXBean。 這兩個bean都使用相同的documentService服務類,它使用相同的DAO類從Oracle數據庫中獲取數據。 DocumentMBean正確返回數據。 DocumentMXBean具有上述錯誤。

有誰知道為什么從類加載器看不到類oracle.ucp.jdbc.LabelableConnection? 只有在我執行MXBean時才會發生這種情況。 我的MBean正確返回數據。 我的WEB-INF / lib文件夾中包含該類的jar文件。 這部署在Tomcat中。 我從Eclipse中啟動Tomcat。

更新1:

我能夠通過將那些“不可見”類的jar文件添加到Eclipse中的Tomcat類路徑來臨時解決這個問題。 看起來像加載MBean,JConsole / java正在使用我的Web應用程序類加載器,它可以訪問類加載器所需的所有庫。 但是在使用Tomcat的類加載器加載MXBeans時,JConsole / java。

我的問題是:在加載MBean或MXBean時,有沒有辦法強制Tomcat / Eclipse / Java使用相同的類加載器(這是我的Web應用程序類加載器)?

更新2:

我發現在加載我的Web應用程序時,Spring使用Web應用程序的類加載器而Tomcat在加載任何MXBean時,它使用JVM類加載器,它沒有我的oracle類路徑。 因此,解決方法是使用我的類的類加載器而不是JVM中的類加載器。 代碼應該是:


    try
    {
    // your codes here

    // Get the current class-loader. This might be the class-loader from Tomcat
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();

    // Set the class-loader to be the one from the DO and not the one from Tomcat
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

    // your codes here
    }
    catch (Exception e)
    {
       // your codes here
    }
    finally
    {
       // Remember to set back the original class-loader
       Thread.currentThread().setContextClassLoader(contextClassLoader);
    }

MXBean可能是由容器類加載器加載的,而不是由Web應用程序加載的。 如果驅動程序位於應用程序li​​b目錄中,那么這將導致您遇到的問題。

如果是這種情況,請將驅動程序移動到tomcat / lib目錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM