Skip to main content

How to map Global JNDI name and ENC.

2 replies [Last post]
arunkumark007
Offline
Joined: 2009-06-24

In Glassfish, I have created a global JNDI name :

JNDI name = jdbc/abcd .

And in my code, I tried to inject the resource with the same name:

@Resource(name="jdbc/abcd")
private static DataSource ds;

I assume that this will be interpreted as Environment Naming Context (ENC) name : java:comp/env/jdbc/abcd .

Fortunately I think Glassfish will automatically resolve ENC name to global JNDI name if a resource with the same Global JNDI name exists.

But what if I have :

@Resource (name="Some_Portable_JNDI_Name")
DataSource ds;

And still my global JNDI name on server is jdbc/abcd.

How to provide the mapping between ENC (java:comp/env/Some_Portable_JNDI_Name) and Global JNDI name (jdbc/abcd) in this case?

I think I have to provide this mapping in Glassfish specific deployment descriptor?
May I know waht is that and how to provide mapping?

I dont want to rely on mappedName property of @Resource annotation as that makes code difficult to port.

Can you please tell me which file I have to use to map these two?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
arunkumark007
Offline
Joined: 2009-06-24

Sahoo,

Thank you so much for your quick reply. It helped me.

Yes I followed your suggestion and its working.

I have one more related question.

Cant I inject the @Resource with ENC name like

@Resource(name="java:comp/env/Some_Portable_ENC_JNDI_Name").

?

I thought container would anyway translate "Some_Portable_ENC_JNDI_Name" in
@Resource(name="Some_Portable_ENC_JNDI_Name").

to "java:comp/env/Some_Portable_ENC_JNDI_Name". Why cant I directly mention ENC name while injection ? Any idea ?

Sahoo

see inline...

glassfish@javadesktop.org wrote:
> In Glassfish, I have created a global JNDI name :
>
> JNDI name = jdbc/abcd .
>
> And in my code, I tried to inject the resource with the same name:
>
> @Resource(name="jdbc/abcd")
> private static DataSource ds;
>
> I assume that this will be interpreted as Environment Naming Context (ENC) name : java:comp/env/jdbc/abcd .
>
> Fortunately I think Glassfish will automatically resolve ENC name to global JNDI name if a resource with the same Global JNDI name exists.
>
I also think GlassFish does this automatic mapping. See [1].
> But what if I have :
>
> @Resource (name="Some_Portable_JNDI_Name")
> DataSource ds;
>
> And still my global JNDI name on server is jdbc/abcd.
>
> How to provide the mapping between ENC (java:comp/env/Some_Portable_JNDI_Name) and Global JNDI name (jdbc/abcd) in this case?
>
> I think I have to provide this mapping in Glassfish specific deployment descriptor?
> May I know waht is that and how to provide mapping?
>
> I dont want to rely on mappedName property of @Resource annotation as that makes code difficult to port.
>
> Can you please tell me which file I have to use to map these two?
>
You can use sun-*.xml deployment descriptors to map component specific
name to global JNDI name. e.g., if you are developing EJBs, then use
sun-ejb-jar.xml; for web, use sun-web.xml. You can specify something
like this in that file:


Some_Portable_JNDI_Name

jdbc/abcd

See [1] for details.

Sahoo.

[1] http://docs.sun.com/app/docs/doc/819-3659/beanr?a=view
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net