2012-05-18 3 views
3

이 문제를보고 해결 한 사람이 있으면 좋겠어요. 나는 MBean과 MXBean 클래스를 가지고있다. 둘 다 동일한 서비스 클래스를 사용하여 DAO 클래스를 통해 데이터베이스에 액세스합니다. 그 클래스를 초기화하고 JConsole을 사용하여 해당 빈을 테스트하는 데 Spring 3.0을 사용하고 있습니다. 이 두 bean은 service 클래스에 액세스 할 때 동일한 메소드 이름을 가지며 methodA()라고 말할 수 있습니다. 그러나 오라클 데이터베이스에 연결할 때 MBean 클래스 만 데이터를 반환합니다. 다른 MXBean 클래스는 에러를 발생시킵니다. 여기 JConsole을 통해 데이터베이스에 연결하도록 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입니다. 두 콩은 동일한 documentService 서비스 클래스를 사용하는데, 이는 동일한 DAO 클래스를 사용하여 Oracle 데이터베이스에서 데이터를 가져옵니다. DocumentMBean는 데이터를 올바르게 반환합니다. DocumentMXBean에는 위에서 언급 한 오류가 있습니다.

클래스 oracle.ucp.jdbc.LabelableConnection 클래스가 클래스 로더에서 보이지 않는 이유를 알고 있습니까? 이것은 MXBean을 실행할 때만 발생합니다. 내 MBean이 데이터를 올바르게 반환합니다. 내 WEB-INF/lib 폴더 안에 해당 클래스를 포함하는 jar 파일이 있습니다. 그리고 이것은 Tomcat에 배포됩니다. Eclipse 내에서 Tomcat을 시작합니다.

업데이트 1 :

나는 이클립스 내부 톰캣의 클래스 경로에 이러한 "보이지 않는"클래스 jar 파일을 추가하여 일시적으로 해결이 할 수 있었다. MBeans를로드하는 것처럼 보이지만, JConsole/java는 클래스 로더가 필요로하는 모든 라이브러리에 액세스 할 수있는 웹 응용 프로그램 클래스 로더를 사용합니다. 그러나 Tomcat의 클래스 로더를 사용하여 MXBeans, JConsole/java를로드 할 때.

제 질문은 : MBean 또는 MXBean을로드 할 때 동일한 클래스 로더 (내 웹 앱 클래스 로더)를 사용하여 Tomcat/Eclipse/Java를 강제 실행하는 방법이 있습니까?

업데이트 2 : 내 웹 응용 프로그램을로드 할 때 어떤 MXBean의를로드 할 때 Tomcat이, 그것은 JVM 클래스 로더를 사용하는 반면, 봄이하지 않는 웹 응용 프로그램의 클래스 로더를 사용하는 것을 발견

내 오라클 클래스 경로. 따라서 해결 방법은 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); 
    } 

답변

0

MXBean이 웹 응용 프로그램이 아닌 컨테이너 클래스 로더에 의해로드되고있는 것 같습니다. 드라이버가 응용 프로그램의 lib 디렉터리에 있으면 문제가 발생할 수 있습니다.

이 경우 드라이버를 tomcat/lib 디렉토리로 이동하십시오.

+0

응답 해 주셔서 감사합니다. 이 작업을 수행하려면 응용 프로그램의 lib 폴더에 모든 jar 파일이 있어야합니다. MXBean에 tomcat/lib 폴더로 이동하지 않고 jar 파일에 대한 액세스 권한을 부여하는 방법이 있습니까? BTW, 나는 당신의 제안을 시도했지만 작동하지 않았다. – Tuan