简体   繁体   English

如何在Jboss 7中使用jndi数据源

[英]How to use jndi datasource in Jboss 7

In Jboss 5 i used a datasource for a remote DB, something as: 在Jboss 5中,我将数据源用于远程DB,如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<datasources>
    <local-tx-datasource>
         <jndi-name>dsName</jndi-name>
          ...
         <connection-url>jdbc:oracle:thin:@xxx:2074:xx</connection-url>
    </local-tx-datasource>
</datasources>

and i called from my applicationContext.xml in this way: 我以这种方式从applicationContext.xml调用:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:dsName"/>
</bean>

it is possibile to do in Jboss7? 在Jboss7中可以做到吗? In these posts JBoss 7.1 - declare datasource and access via JNDI https://developer.jboss.org/thread/196876 在这些文章中, JBoss 7.1-声明数据源和通过JNDI https://developer.jboss.org/thread/196876进行 访问

i have found that "Remote lookup of datasources is not supported in AS7." 我发现“ AS7不支持数据源的远程查找。”

Thanks 谢谢

WildFly (and AS7) don't support remote datasource lookup, which I believe is a deliberate decision. WildFly(和AS7)不支持远程数据源查找,我认为这是一个故意的决定。 If you used it on older versions where it worked, it was incredibly easy to create terrible performance problems, large server-side memory leaks, and more. 如果您在适用的较旧版本上使用它,则很容易造成可怕的性能问题,大量服务器端内存泄漏等。

What was the use case for having one? 拥有一个的用例是什么? The best option is usually to encapsulate the data logic in an EJB which does the DB work server-side, and then call it from the client. 最好的选择通常是将数据逻辑封装在由DB在服务器端进行工作的EJB中,然后从客户端调用它。

Source discussion 来源讨论

That said I am not sure if you are actually trying to use "remote" datasource lookup. 那就是说,我不确定您是否真的在尝试使用“远程”数据源查找。 Check out the guides for datasource configuration basics. 查看有关数据源配置基础的指南。

Create DataSource using JBoss 7 JNDI and Spring 使用JBoss 7 JNDI和Spring创建数据源

Data Source Configuration in AS 7 AS 7中的数据源配置

i get 我得到

Error creating bean with name 'dataSource' defined in URL [file:... applicationContext.xml]: Invocation of init method failed; 使用URL [file:... applicationContext.xml]中定义的名称为'dataSource'的bean创建时出错:调用init方法失败; nested exception is javax.naming.CommunicationException: Failed to connect to any server. 嵌套的异常是javax.naming.CommunicationException:无法连接到任何服务器。 Servers tried: [remote://localhost:4447 (java.net.ConnectException: Connection refused: no further information)] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1708) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1708)上尝试的服务器:[远程://本地主机:4447(java.net.ConnectException:连接被拒绝:没有更多信息)]

it works only if i configure the datasource in this way: 它仅在我以这种方式配置数据源时才有效:

        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
           <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
               <property name="url"  >
                  <value>...</value>
               </property>
               <property name="username"  >
                  <value>...</value>
               </property>
               <property name="password"  >
                  <value>...</value>
               </property>


         </bean>

without jndi, directly in applicationContext.xml 没有jndi,直接在applicationContext.xml中

thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM