-
1. Re: [Newbie]: DataSource not binding to java:comp/env
ovidiu.feodorov Jun 7, 2004 9:07 PM (in response to pani_rd)Your component should look up the resouce factory in its Enterprise Naming Context ("java:comp/env") using a resource reference. For that:
1. Declare a resouce reference in ejb-jar.xml:<session> <ejb-name>MySession</ejb-name> ... <resource-ref> <res-ref-name>jdbc/PostgresDS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Sharable</res-sharing-scope> </resource-ref> </session>
2. Declare the mapping to the actual JNDI name in jboss.xml:<session> <ejb-name>MySession</ejb-name> ... <resource-ref> <res-ref-name>jdbc/PostgresDS</res-ref-name> <jndi-name>jdbc/PostgresDS</jndi-name> </resource-ref> </session>
3. Look it up:Context initCtx = new InitialContext(); Context compEnv = (Context)initCtx.lookup("java:comp/env"); DataSource ds = (DataSource)initCtx.lookup("jdbc/PostgresDS");
-
2. Re: [Newbie]: DataSource not binding to java:comp/env
lepe Jun 8, 2004 3:23 AM (in response to pani_rd)Hm... looks to me that you should have a closer look on the last lookup - shouldn't compEnv be used instead ;)
Context initCtx = new InitialContext();
Context compEnv = (Context)initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)initCtx.lookup("jdbc/PostgresDS");
/L -
3. Re: [Newbie]: DataSource not binding to java:comp/env
pani_rd Jun 8, 2004 11:28 AM (in response to pani_rd)Thanks for the reply.
I understand that I can define a resource reference and look-up for the resource reference in the ENC and access an object that's tied to that Context.
Also, my understanding is that ENC are declared in the client side, meaning from the place where you want to access the server side objects tied in a NamingService via JNDI.
Now, my question is; In the NamingService, I want to BIND the DataSource Object to the name "jdbc/PostgresDS" in the context "java:comp" rather than "java:"
So, when I access it then I can define a resource-ref in the jboss-xml, so that the client would get a reference from "env".
OR
I can access it directly by looking up for "java:comp/jdbc/PostgresDS"
After doing all the reading about JBoss NS Architecture, I concluded it is not possible in 3.2.3. Please correct me if 'am wrong.
Thanks,
Pani -
4. Re: [Newbie]: DataSource not binding to java:comp/env
ovidiu.feodorov Jun 8, 2004 12:38 PM (in response to pani_rd)Yes, obviously step 3 should be:
Context initCtx = new InitialContext(); Context compEnv = (Context)initCtx.lookup("java:comp/env"); DataSource ds = compEnv.lookup("jdbc/MyAccessToPostgresDS");
It wouldn't make sense to look up compEnv and not use it. I type faster than I think :).
As for the last reply on the topic: ENC is private to each application component. An application component environment is a local environment that is accessible only by the component when the container's thread of control is interacting with it. Bean2 cannot access "java:comp" of Bean1 and viceversa. You cannot externally bind something into a component's "java:comp". You cannot access a component's ENC from client-side, you can only access it from inside the component, while the component is deployed in the application server.
JBossNS has three levels of naming scope:
- "java:comp" - can be accessed only by the component.
- "java:" - can be accessed only from the application server VM.
- and everything else. -
5. Re: [Newbie]: DataSource not binding to java:comp/env
pani_rd Jun 8, 2004 4:04 PM (in response to pani_rd)As for the last reply on the topic: ENC is private to each application component. An application component environment is a local environment that is accessible only by the component when the container's thread of control is interacting with it. Bean2 cannot access "java:comp" of Bean1 and viceversa. You cannot externally bind something into a component's "java:comp". You cannot access a component's ENC from client-side, you can only access it from inside the component, while the component is deployed in the application server.
Thanks for the response.
I'm not using any EJB component as of now. Just got my Web Component and trying to access the Data Source. So, does this mean it is not possible to bind the datasource to java:comp to be able to access from my web component? -
6. Re: [Newbie]: DataSource not binding to java:comp/env
ovidiu.feodorov Jun 8, 2004 6:12 PM (in response to pani_rd)It is similar for web applications. Use resource-ref.