jndi

How does the EJB client locate the EJB server without url?

落爺英雄遲暮 提交于 2019-11-27 16:12:47
问题 I am new to Java EE. At present I am going through The Java EE 6 Tutorial, Volume 1 (Basic Concepts Beta) by Sun Microsystems. To escape from monotonous reading time to time I play with few Java EE projects/codes written by others. I came from SE. My head is still filled with SE. In SE ( two tier application) I use DATABASE_URL = "jdbc:mysql://something.db_server.com/db_name" This is how my client knows where the database server is. In one Java EE example I saw // Access JNDI Initial Context.

Spring MVC 使用 JNDI 配置的DataSource

无人久伴 提交于 2019-11-27 13:26:56
稍微看了下,Spring 中JNDI 的使用,弄了个小例子。有很多不完备的地方,以后慢慢看,再改吧。 <一> 技术使用 Spring MVC JDBC Template Maven JNDI <二> 一些配置 Maven POM 配置 spring-context、spring-webmvc、spring-orm、spring-jdbc、mysql-connector-java等 创建数据库 create database usersdb; CREATE TABLE `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(45) NOT NULL, `password` varchar(45) NOT NULL, `email` varchar(45) NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1 3.在Tomcat 中配置JNDI 数据源 也可以在其它地方配置,比如web.xml 中配置。这个配置,是为了JNDI 能够查找到该数据源。 <Resource name="jdbc/UsersDB" auth="Container" type="javax.sql

Setting up JNDI Datasource in jUnit

左心房为你撑大大i 提交于 2019-11-27 13:17:13
I am trying to set up some jUnit testing. Our database is connected by the server using JNDI. We have an xml describing the setup in root.xml. How do I set up jUnit to hook up to the database? I'd prefer to have it just read the the stuff off of root.xml, but I'm open to setting it up anyway that works. I've found this Blog: https://blogs.oracle.com/randystuph/entry/injecting_jndi_datasources_for_junit About H2 Datasource: http://www.h2database.com/javadoc/org/h2/jdbcx/JdbcConnectionPool.html So for my Code: package com.example.test; import java.sql.Connection; import java.sql.ResultSet;

Initialcontext in a standalone Java program

﹥>﹥吖頭↗ 提交于 2019-11-27 12:57:01
问题 I'm using a JNDI for creating tomcat connection pool. It works great in a web application. I believe the InitialContext is provided by the tomcat server. Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env"); dataSource = (DataSource)envContext.lookup("jdbc/testdb"); But when I try to call the same utility from a standalone Java program, the initContext object is null. How can I explicitly provide all the necessary properties that

Easy way to start a standalone JNDI server (and register some resources)

↘锁芯ラ 提交于 2019-11-27 12:31:49
问题 For testing purposes, I'm looking for a simple way to start a standalone JNDI server, and bind my javax.sql.DataSource to "java:/comp/env/jdbc/mydatasource" programmatically. The server should bind itself to some URL, for example: "java.naming.provider.url=jnp://localhost:1099" (doesn't have to be JNP), so that I can look up my datasource from another process. I don't care about which JNDI server implementation I'll have to use (but I don't want to start a full-blown JavaEE server). This

Configure Multiple DataSource in Spring Boot with JNDI

我与影子孤独终老i 提交于 2019-11-27 11:23:06
问题 I want to manage multiple DataSource using your Application Servers built-in features and access it using JNDI. I am using Spring boot with Spring JPA data. I am able to configure the application.properties for single datasource: spring.datasource.jndi-name=jdbc/customers And my configuration in context.xml file as below: <Resource name="jdbc/customer" auth="Container" type="javax.sql.DataSource" maxTotal="100" maxIdle="30" maxWaitMillis="10000" username="root" password="root" driverClassName

Should you set up database connection properties in server.xml or context.xml

浪子不回头ぞ 提交于 2019-11-27 10:11:24
I am trying to set up the database connection properties using JNDI for a Spring web application. I am considering two approaches as below: Approach 1: In your Spring configuration you may have something like: <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/facs"/> Then in your webapp /META-INF/context.xml file you should have something similar too: <?xml version='1.0' encoding='utf-8'?> <!-- antiResourceLocking="true" --> <Context path="/podd-apn" reloadable="true" cachingAllowed="false" antiResourceLocking="true" > <Resource name="jdbc/facs" type="javax.sql.DataSource"

How can i config module and application name for JNDI Lookups

亡梦爱人 提交于 2019-11-27 10:10:59
问题 In EJB 3.1 JNDI Lookups can be made with different Lookup-Names: java:global[/<app-name>]/<module-name>/<bean-name>!<fully-qualifiedbean interface-name> java:global[/<app-name>]/<module-name>/<bean-name> java:app/<module-name>/<bean-name>!<fully-qualified-bean-interface-name> java:app/<module-name>/<bean-name> java:module/<bean-name>!<fully-qualified-bean-interface-name> java:module/<bean-name> In my JavaEE 6 Project (with Maven 2, Netbeans 6 and Glassfish v3) the Application name is X

what is java:comp/env?

偶尔善良 提交于 2019-11-27 09:07:06
问题 what is meant by java:comp/env ? What does the look up like : Context envContext = (Context)initContext.lookup("java:comp/env"); do ? I understand that a look-up like : (DataSource)envContext.lookup("jdbc/MyDatasource") looks up for the name MyDatasource in the context.xml or web.xml to get the URL of the database. Is it so ? !! But what does the former look up do ? 回答1: java:comp/env is the node in the JNDI tree where you can find properties for the current Java EE component (a webapp, or an

Proper usage of JDBC Connection Pool (Glassfish)

孤街醉人 提交于 2019-11-27 08:44:50
I need a database connection in Java Web service implemented as a session bean, and I'm not sure if I do it right. I created a class public final class SQLUtils { //..... private static DataSource m_ds=null; static { try { InitialContext ic = new InitialContext(); m_ds = (DataSource) ic.lookup(dbName); //Connection pool and jdbc resource previously created in Glassfish , dbName contains the proper JNDI resource name } catch (Exception e) { e.printStackTrace(); m_ds = null; } } public static Connection getSQLConnection() throws SQLException { return m_ds.getConnection(); } } Whenever I need a