You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by laredotornado <la...@gmail.com> on 2012/09/04 23:16:18 UTC
What JNDI name does a datasource get bound to?
Hi,
I'm using OpenEJB 4.0.0. When I use openEjb to create a datasource, what
JNDI name does it get bound to? When I create my datasource as recommended
by the documentation …
final Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
p.setProperty("openejb.deployments.classpath.include", ".*");
p.put("openejb.descriptors.output", "true");
// Inject data source
final Properties props = loadMyProjectProps();
final String dsJndiName = props.getProperty("DATASOURCE_JNDI_PREFIX") +
"MySqlDS";
System.out.println("ds jndi name:" + dsJndiName);
p.put(dsJndiName, "new://Resource?type=DataSource");
p.put(dsJndiName + ".JdbcDriver", "com.mysql.jdbc.Driver");
final String url = "jdbc:mysql://" + props.getProperty("DB_SERVER") + ":"
+ props.getProperty("DB_PORT") + "/" + props.getProperty("DB_NAME");
p.put(dsJndiName + ".JdbcUrl", url);
p.put(dsJndiName + ".Username", props.getProperty("DB_USER"));
p.put(dsJndiName + ".Password", props.getProperty("DB_PASSWORD"));
p.put(dsJndiName + ".JtaManaged", "true");
final InitialContext initialContext = new InitialContext(p);
it doesn't seem to get bound to any JNDI name. I verify this by listing
everything in my context (and through OpenEJB debugging) …
System.out.println("initial context jndi names:");
NamingEnumeration<NameClassPair> list = initialContext.list("");
while (list.hasMore()) {
final NameClassPair ncp = list.next();
System.out.println("\tname:" + ncp.getName() + " class:" +
ncp.getClassName());
}
System.out.println("========================");
Nothing is listed for my datasource, whose JNDI name in the above example
happens to be "java:MySqlDS".
Thanks for any advice, - Dave
--
View this message in context: http://openejb.979440.n4.nabble.com/What-JNDI-name-does-a-datasource-get-bound-to-tp4657277.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: RES: What JNDI name does a datasource get bound to?
Posted by Romain Manni-Bucau <rm...@gmail.com>.
You cant. Here the solutions for portability i have in mind now:
1) use relative naming for injections
2) use java:app or java:global (on snapshot i guess, no more sure)
Le 5 sept. 2012 18:34, "laredotornado" <la...@gmail.com> a écrit :
> Thanks for the reply. The pattern was indeed
> "java:openejb/Resource/MySqlDS". However, I'm using some Spring code that
> relies on JBoss-style JNDI names for the datasource, so it's expecting
> "java:MySqlDS". How can I make the resource get bound to that? I've tried
> using the "openejb.jndiname.format" property ...
>
> final Properties props = loadMyProjectProps();
> final String dsJndiName = "MySqlDS"; ;
> p.put(dsJndiName, "new://Resource?type=DataSource");
> p.put(dsJndiName + ".JdbcDriver", "com.mysql.jdbc.Driver");
> final String url = "jdbc:mysql://" +
> props.getProperty("DB_SERVER") +
> ":" + props.getProperty("DB_PORT") + "/" + props.getProperty("DB_NAME");
> p.put(dsJndiName + ".JdbcUrl", url);
> p.put(dsJndiName + ".Username", props.getProperty("DB_USER"));
> p.put(dsJndiName + ".Password",
> props.getProperty("DB_PASSWORD"));
> p.put(dsJndiName + ".JtaManaged", "true");
> p.put("openejb.jndiname.format", "{ejbName}");
> final InitialContext initialContext = new InitialContext(p);
>
> but it's having no effect -- the datasource still gets bound to
> "java:openejb/Resource/MySqlDS". Thanks for any additional help, - Dave
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/What-JNDI-name-does-a-datasource-get-bound-to-tp4657277p4657295.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: RES: What JNDI name does a datasource get bound to?
Posted by laredotornado <la...@gmail.com>.
Thanks for the reply. The pattern was indeed
"java:openejb/Resource/MySqlDS". However, I'm using some Spring code that
relies on JBoss-style JNDI names for the datasource, so it's expecting
"java:MySqlDS". How can I make the resource get bound to that? I've tried
using the "openejb.jndiname.format" property ...
final Properties props = loadMyProjectProps();
final String dsJndiName = "MySqlDS"; ;
p.put(dsJndiName, "new://Resource?type=DataSource");
p.put(dsJndiName + ".JdbcDriver", "com.mysql.jdbc.Driver");
final String url = "jdbc:mysql://" + props.getProperty("DB_SERVER") +
":" + props.getProperty("DB_PORT") + "/" + props.getProperty("DB_NAME");
p.put(dsJndiName + ".JdbcUrl", url);
p.put(dsJndiName + ".Username", props.getProperty("DB_USER"));
p.put(dsJndiName + ".Password", props.getProperty("DB_PASSWORD"));
p.put(dsJndiName + ".JtaManaged", "true");
p.put("openejb.jndiname.format", "{ejbName}");
final InitialContext initialContext = new InitialContext(p);
but it's having no effect -- the datasource still gets bound to
"java:openejb/Resource/MySqlDS". Thanks for any additional help, - Dave
--
View this message in context: http://openejb.979440.n4.nabble.com/What-JNDI-name-does-a-datasource-get-bound-to-tp4657277p4657295.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
RES: What JNDI name does a datasource get bound to?
Posted by Elton Kuzniewski <el...@softplan.com.br>.
Hello
Try follow pattern:
java:openejb/Resource/MySqlDS
where MySqlDS is the name of your DS.
Att,
Elton Kuzniewski
Analista de Sup. Desenvolvimento e Arquitetura
CSM, SCJA, SCJP 5, SCWCD 5, SCBCD 5
Pesquisa & Desenvolvimento
Softplan/Poligraph
+ 55 48 3027-8000
www.softplan.com.br
-----Mensagem original-----
De: laredotornado [mailto:laredotornado@gmail.com]
Enviada em: terça-feira, 4 de setembro de 2012 18:16
Para: users@openejb.apache.org
Assunto: What JNDI name does a datasource get bound to?
Hi,
I'm using OpenEJB 4.0.0. When I use openEjb to create a datasource, what
JNDI name does it get bound to? When I create my datasource as recommended
by the documentation …
final Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
p.setProperty("openejb.deployments.classpath.include", ".*");
p.put("openejb.descriptors.output", "true");
// Inject data source
final Properties props = loadMyProjectProps();
final String dsJndiName = props.getProperty("DATASOURCE_JNDI_PREFIX") +
"MySqlDS";
System.out.println("ds jndi name:" + dsJndiName);
p.put(dsJndiName, "new://Resource?type=DataSource");
p.put(dsJndiName + ".JdbcDriver", "com.mysql.jdbc.Driver");
final String url = "jdbc:mysql://" + props.getProperty("DB_SERVER") + ":"
+ props.getProperty("DB_PORT") + "/" + props.getProperty("DB_NAME");
p.put(dsJndiName + ".JdbcUrl", url);
p.put(dsJndiName + ".Username", props.getProperty("DB_USER"));
p.put(dsJndiName + ".Password", props.getProperty("DB_PASSWORD"));
p.put(dsJndiName + ".JtaManaged", "true");
final InitialContext initialContext = new InitialContext(p);
it doesn't seem to get bound to any JNDI name. I verify this by listing
everything in my context (and through OpenEJB debugging) …
System.out.println("initial context jndi names:");
NamingEnumeration<NameClassPair> list = initialContext.list("");
while (list.hasMore()) {
final NameClassPair ncp = list.next();
System.out.println("\tname:" + ncp.getName() + " class:" +
ncp.getClassName());
}
System.out.println("========================");
Nothing is listed for my datasource, whose JNDI name in the above example
happens to be "java:MySqlDS".
Thanks for any advice, - Dave
--
View this message in context: http://openejb.979440.n4.nabble.com/What-JNDI-name-does-a-datasource-get-bound-to-tp4657277.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: What JNDI name does a datasource get bound to?
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Try openejb:Resource/MyDS
Le 4 sept. 2012 23:27, "laredotornado" <la...@gmail.com> a écrit :
> Hi,
>
> I'm using OpenEJB 4.0.0. When I use openEjb to create a datasource, what
> JNDI name does it get bound to? When I create my datasource as recommended
> by the documentation …
>
> final Properties p = new Properties();
> p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
> p.setProperty("openejb.deployments.classpath.include",
> ".*");
> p.put("openejb.descriptors.output", "true");
>
> // Inject data source
> final Properties props = loadMyProjectProps();
> final String dsJndiName =
> props.getProperty("DATASOURCE_JNDI_PREFIX") +
> "MySqlDS";
> System.out.println("ds jndi name:" + dsJndiName);
> p.put(dsJndiName, "new://Resource?type=DataSource");
> p.put(dsJndiName + ".JdbcDriver", "com.mysql.jdbc.Driver");
> final String url = "jdbc:mysql://" +
> props.getProperty("DB_SERVER") + ":"
> + props.getProperty("DB_PORT") + "/" + props.getProperty("DB_NAME");
> p.put(dsJndiName + ".JdbcUrl", url);
> p.put(dsJndiName + ".Username",
> props.getProperty("DB_USER"));
> p.put(dsJndiName + ".Password",
> props.getProperty("DB_PASSWORD"));
> p.put(dsJndiName + ".JtaManaged", "true");
> final InitialContext initialContext = new
> InitialContext(p);
>
> it doesn't seem to get bound to any JNDI name. I verify this by listing
> everything in my context (and through OpenEJB debugging) …
>
> System.out.println("initial context jndi names:");
> NamingEnumeration<NameClassPair> list =
> initialContext.list("");
> while (list.hasMore()) {
> final NameClassPair ncp = list.next();
> System.out.println("\tname:" + ncp.getName() + "
> class:" +
> ncp.getClassName());
> }
> System.out.println("========================");
>
> Nothing is listed for my datasource, whose JNDI name in the above example
> happens to be "java:MySqlDS".
>
> Thanks for any advice, - Dave
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/What-JNDI-name-does-a-datasource-get-bound-to-tp4657277.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>