3

この問題を見て解決した人がいれば幸いです。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 アプリケーション クラス ローダーを使用しているようです。ただし、MXBeans をロードする場合は、Tomcat のクラス ローダーを使用して 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);
    }
4

1 に答える 1

0

MXBeanは、Webアプリケーションではなく、コンテナクラスローダーによってロードされている可能性があります。ドライバがアプリケーションのlibディレクトリにある場合、これにより問題が発生します。

この場合は、ドライバーをtomcat/libディレクトリーに移動してください。

于 2012-05-19T20:10:14.637 に答える