简体   繁体   中英

JBoss AS 7 datasource configuration issue

I'm trying to retrieve a dataSource object from thr jndi -configuration inside the standalone.xml . 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 = null;
try {
    dataSource = (DataSource) jndi.lookup("java:jboss/datasources/introDB");
} catch (NamingException e) { }

But the code throws an Exception, like 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 . If you want to use jndi name like datasources/introDB you should type it without the java: prefix. So, the correct jndi-name is

jndi-name=datasources/introDB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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