jndi

在Tomcat中配置JNDI数据源

隐身守侯 提交于 2020-01-15 08:38:12
先了解一些基本概念。 JNDI JNDI是用于向Java程序提供目录和命名功能的API。 它被设计成独立于特定的目录服务,各种各样的目录都可以通过相同的方式进行访问。可以简单地把JNDI理解为一种将对象和名字绑定的技术,对象工厂负责生产出对象,这些对象都和惟一的名字绑定。外部程序可以通过名字来获取对某个对象的引用。 数据源 数据源(DataSource)是一个用来存储数据的工具,它可以是复杂的大型企业级数据库,也可以是简单得只有行和列的文件。它可以位于在服务器端,也可以位于客服端。 一个DataSource对象就是一个用于提供连接数据库的工具,它通常与连接池共同使用。在数据源初始化时,事先建立了多个数据库连接,这些数据库连接保存在连接池(Connect Pool)中。当Java程序访问数据库时,只需要从连接池中取出空闲状态的数据库连接;当程序访问数据库结束,再将数据库连接放回连接池。 在JDBC 2.0或JDBC 3.0中,所有的数据库驱动程序提供商必须提供一个实现了DataSource接口的类,并要求使用数据源必须首先在JNDI中注册该数据源对象。 相比于传统的DriverManager接口,使用DataSource对象建立数据库的连接更加高效,虽然两者的使用范围都很相似,但DataSource比起DriverManager有两个方面的优势: 灵活

problem configure JBoss to work with JNDI(2)

自闭症网瘾萝莉.ら 提交于 2020-01-14 13:58:11
问题 in continuation to the question from last week: problem configure JBoss to work with JNDI I'm trying to bind datasource in JBoss and use it in my application. In my struggling, I already managed to avoid the javax.naming.NameNotFoundException by: 1. using in java new InitialContext().lookup(connection); instead of new JndiObjectFactoryBean().setJndiName(connection); 2. changing the connection name from: 'jndi-name' to 'java:jndi-name' Now the problem is that the datasouce that I get from the

How to set up a <Resource> in Tomcat 7 so that I don't need to use “java:/comp/env” in the code?

蹲街弑〆低调 提交于 2020-01-14 08:01:06
问题 I am new to setting up JNDI resources and setting up JNDI resources in Tomcat. I inherited a servlet application. It runs on a test server via WebLogic. The servlet application accesses its database resource in the following way: ctx = new InitialContext(); ds = (javax.sql.DataSource)ctx.lookup("myDataBaseName"); conn = ds.getConnection(); When I tried that in a test JSP it doesn't work. I get javax.naming.NameNotFoundException: Name myDataBaseName is not bound in this Context However I was

Simple JNDI ContextFactory?

走远了吗. 提交于 2020-01-14 04:53:07
问题 My WAR application is deployed to Amazon Elastic Beanstalk. They don't support JNDI, but I need it for JPA and unit tests. What JNDI context factory I can use as a workaround? I need a simple open source solution, that would allow me to configure entire factory through jndi.properties . I tried GuiceyFruit, but looks like it doesn't allow data source configuration inside one file. Any suggestions? ps. OpenEJB will work, but it's an overkill for such a simple task 回答1: Try Simple-JNDI. It

How to lookup EJB using JNDI in WebSphere Liberty

≡放荡痞女 提交于 2020-01-14 03:18:06
问题 I am trying to perform a JNDI name search using Liberty Application Server.However, It is throwing me a dependency injection issue.Attached is my code I am getting the following Error: [ERROR ] SRVE0319E: For the [com.airline.controllers.FlightDetails] servlet, com.airline.controllers.FlightDetails servlet class was found, but a resource injection failure has occurred. CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/com.airline.controllers.FlightDetails

Publishing EJB's local interface in weblogic

只谈情不闲聊 提交于 2020-01-13 06:11:29
问题 is there a way to lookup an EJB in weblogic if it implements only local interface? If I use this @Remote public interface TestSessionRemote { public void businessMethod(); } @Stateless(mappedName = "A") public class TestSessionBean implements TestSessionRemote { public void businessMethod() { } } the EJB can be looked up using this name: "A#" + TestSessionRemote.class.getName() If I change the annotation for TestSessionRemote from @Remote to @Local the EJB disappears from JNDI. Is there a way

Publishing EJB's local interface in weblogic

旧城冷巷雨未停 提交于 2020-01-13 06:11:29
问题 is there a way to lookup an EJB in weblogic if it implements only local interface? If I use this @Remote public interface TestSessionRemote { public void businessMethod(); } @Stateless(mappedName = "A") public class TestSessionBean implements TestSessionRemote { public void businessMethod() { } } the EJB can be looked up using this name: "A#" + TestSessionRemote.class.getName() If I change the annotation for TestSessionRemote from @Remote to @Local the EJB disappears from JNDI. Is there a way

jndi database connection with jpa and eclipselink

你离开我真会死。 提交于 2020-01-12 07:24:28
问题 I try to setup a database connection in java with JNDI in combination with eclipseLink/JPA on Tomcat 5.5. I already configured the JNDI resource in web.xml and context.xml. The db connection works with JNDI without using JPA and eclipseLink. After configuring the persistence.xml for eclipseLink, I got the following exception. I don't know how to configure the persistence.xml correctly to use JNDI datasource for the db connection. The exception WicketMessage: Method onFormSubmitted of

Glassfish v3 / JNDI entry cannot be found problems!

冷暖自知 提交于 2020-01-12 03:28:10
问题 I've been having problems trying to call an EJB's method from a Java Application Client. Here is the code. EJB Remote Interface package com.test; import javax.ejb.Remote; @Remote public interface HelloBeanRemote { public String sayHello(); } EJB package com.test; import javax.ejb.Stateless; @Stateless (name="HelloBeanExample" , mappedName="ejb/HelloBean") public class HelloBean implements HelloBeanRemote { @Override public String sayHello(){ return "hola"; } } Main class (another project)

Glassfish v3 / JNDI entry cannot be found problems!

為{幸葍}努か 提交于 2020-01-12 03:28:06
问题 I've been having problems trying to call an EJB's method from a Java Application Client. Here is the code. EJB Remote Interface package com.test; import javax.ejb.Remote; @Remote public interface HelloBeanRemote { public String sayHello(); } EJB package com.test; import javax.ejb.Stateless; @Stateless (name="HelloBeanExample" , mappedName="ejb/HelloBean") public class HelloBean implements HelloBeanRemote { @Override public String sayHello(){ return "hola"; } } Main class (another project)