从Web容器外部访问数据源(通过JNDI) [英] Accessing Datasource from Outside A Web Container (through JNDI)
问题描述
我正试图从容器外部的胖客户端访问Web容器(JBoss)中定义的数据源。
I'm trying to access a data source that is defined within a web container (JBoss) from a fat client outside the container.
我决定通过JNDI查找数据源。实际上,我的持久性框架(Ibatis)就是这样做的。
I've decided to look up the data source through JNDI. Actually, my persistence framework (Ibatis) does this.
执行查询时,我总是最终会遇到以下错误:
When performing queries I always end up getting this error:
java.lang.IllegalAccessException: Method=public abstract java.sql.Connection java.sql.Statement.getConnection() throws java.sql.SQLException does not return Serializable
Stacktrace:
org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService.doStatementMethod(WrapperDataSourceS
ervice.java:411),
org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService.invoke(WrapperDataSourceService.java
:223),
sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source),
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25),
java.lang.reflect.Method.invoke(Method.java:585),
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155),
org.jboss.mx.server.Invocation.dispatch(Invocation.java:94),
org.jboss.mx.server.Invocation.invoke(Invocation.java:86),
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264),
org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659),
我的数据源:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/xxxxxDS</jndi-name>
<connection-url>jdbc:oracle:thin:@xxxxxxxxx:1521:xxxxxxx</connection-url>
<use-java-context>false</use-java-context>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>xxxxxxxx</user-name>
<password>xxxxxx</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
</local-tx-datasource>
</datasources>
有人知道这可能来自哪里吗?
Does anyone have a clue where this could come from?
也许有人甚至知道更好的方法来实现这一目标。
任何提示都将不胜感激!
Maybe someone even knows a better way how to achieve this. Any hints are much appreciated!
干杯,
Michael
推荐答案
@Michael Well,java.sql.Connection是一个接口-从JBoss获得的具体实现在技术上可能是可序列化的-但我认为您真的不会有任何可用的选择。如果可能的话,这可能很容易:)
@Michael Well, java.sql.Connection is an Interface - it might technically be possible for the concrete implementation you're getting from JBoss to be Serializable - but I don't think you're really going to have any options you can use. If it was possible, it would probably be easy :)
我认为@toolkit可能已经在虚拟机外部说出了正确的词-JDBC驱动程序将与我猜想本机驱动程序代码在底层操作系统中运行,所以这可能可以解释为什么您不能仅通过其他地方的网络传递连接。
I think @toolkit might have said the right words with useable outside the VM - the JDBC drivers will be talking to native driver code running in the underlying OS I guess, so that might explain why you can't just pass a connection over the network elsewhere.
我的建议,(如果您不要得到更好的建议!)将是寻找另一种方法-如果您有权在JBoss目录中找到资源,则可以实现一个代理对象,您可以从该目录中查找并获取该对象,从而可以使用从胖客户端远程连接。这是一种称为数据传输对象的设计模式,我认为 Wikipedia条目
My advice, (if you don't get any better advice!) would be to find a different approach - if you have access to locate the resource on the JBoss directory, maybe implement a proxy object that you can locate and obtain from the directory that allows you to use the connection remotely from your fat client. That's a design pattern called data transfer object I think Wikipedia entry
这篇关于从Web容器外部访问数据源(通过JNDI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!