How can I create my own resource, which can also be found in a glass planet with java: com / env-scheme?

I created some JDBC resources and user resources in GlassFish. I named the JDBC resource jdbc/mydband user resource service/test.

A JDBC connection is being made with a call ic.lookup("java:comp/env/jdbc/mydb"). It can also be found with help ic.lookup("jdbc/mydb"), which has some flaws, see Robin's answer below.

But my user resource needs to be searched with ic.lookup("service/test"). The line does not work. Is it possible, and if so: how? ic.lookup("java:comp/env/service/test")

+5
source share
4 answers

, Java EE, JNDI. ​​ , .

JDBC, jndi. , , , , , . , .

+3

.xml, , - / domain.xml:

    <resources>
        <!-- JDBC RESOURCE -->
        ...
        <custom-resource res-type="java.lang.String" jndi-name="MyCustomStringResource"
                         factory-class="org.glassfish.resources.custom.factory.PrimitivesAndStringFactory">
            <property name="value" value="hello, this is a string resource"></property>
        </custom-resource>
        ...
    </resources>
    <servers>
        <server name="server" config-ref="server-config">
            <application-ref ref="__admingui" virtual-servers="__asadmin"></application-ref>
            ...
            <resource-ref ref="MyCustomStringResource"></resource-ref>
            ...
        </server>
    </servers>
+1

, Glassfish " ". Java EE , "java: comp/env" , . ,

ic.lookup("java:comp/env/jdbc/mydb")

, jdbc/mydb (EJB/servlet ..), . java: comp/env , .

0

glassfish 3 up admin gui localhost: 4848 gui JDNI > >

for the previous version of glassfish, I would recommend changing glassfish.xml to create a new resource using qualifiers

0
source

All Articles