简体   繁体   English

JBoss AS 7数据源配置问题

[英]JBoss AS 7 datasource configuration issue

I'm trying to retrieve a dataSource object from thr jndi -configuration inside the standalone.xml . 我正在尝试从standalone.xml内的thr jndi configuration检索dataSource对象。 I'm doing that as follows: 我这样做如下:

DataSource configuration: 数据源配置:

<subsystem xmlns="urn:jboss:domain:datasources:1.0">
            <datasources>
                <datasource jndi-name="java:jboss/datasources/introDB" pool-name="introDS" enabled="true" jta="true" use-java-context="true" use-ccm="true">
                    <connection-url>
                        jdbc:postgresql://127.0.0.1:5432/hres
                    </connection-url>
                    <driver>
                        postgresql-9.3-1102.jdbc4
                    </driver>
                    <pool>
                        <prefill>
                            false
                        </prefill>
                        <use-strict-min>
                            false
                        </use-strict-min>
                        <flush-strategy>
                            FailingConnectionOnly
                        </flush-strategy>
                    </pool>
                    <security>
                        <user-name>
                            postgres
                        </user-name>
                        <password>
                            postgres
                        </password>
                    </security>
                    <validation>
                        <validate-on-match>
                            false
                        </validate-on-match>
                        <background-validation>
                            false
                        </background-validation>
                        <useFastFail>
                            false
                        </useFastFail>
                    </validation>
                </datasource>
            </datasources>

Now, I'm trying to get the dataSource object programatically. 现在,我正在尝试以编程方式获取dataSource对象。

DataSource dataSource = null;
try {
    dataSource = (DataSource) jndi.lookup("java:jboss/datasources/introDB");
} catch (NamingException e) { }

But the code throws an Exception, like NameNotFoundException . 但是代码会抛出一个异常,例如NameNotFoundException What did I do wrong? 我做错了什么?

I've found the solution. 我找到了解决方案。 What was wrong was setting up the jndi-name attribute to java:jboss/datasources/introDB . 错误的是将jndi-name属性设置为java:jboss/datasources/introDB If you want to use jndi name like datasources/introDB you should type it without the java: prefix. 如果要使用jndi名称(如datasources/introDB ,则应键入不带java:前缀的名称。 So, the correct jndi-name is 因此,正确的jndi-name

jndi-name=datasources/introDB

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

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