`
dfwang
  • 浏览: 92904 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

JNDI Sample

    博客分类:
  • j2ee
阅读更多



    public class TestJbossJNDI {

    public TestJbossJNDI() {
    super();
    // TODO Auto-generated constructor stub
    }
    public static void main(String[] args) { try {
    Properties env = new Properties();
    //载入jboss的SPI相关参数,包括初始上下文工厂,服务URL,等等
    env.load(new FileInputStream("jbossJndi.properties"));
    env.list(System.out);
    //通过JNDI api 初始化上下文
    InitialContext ctx = new javax.naming.InitialContext(env);
    System.out.println("Got context");
    //create a subContext
    ctx.createSubcontext("/sylilzy");
    ctx.createSubcontext("sylilzy/sily");
    //rebind a object
    ctx.rebind("sylilzy/sily/a", "I am sily a!");
    ctx.rebind("sylilzy/sily/b", "I am sily b!");
    //lookup context
    Context ctx1=(Context)ctx.lookup("sylilzy");
    Context ctx2=(Context)ctx1.lookup("/sylilzy/sily");
    ctx2.bind("/sylilzy/g", "this is g");
    //lookup binded object
    Object o;
    o=ctx1.lookup("sily/a");
    System.out.println("get object from jndi:"+o);
    //rename the object
    ctx2.rename("/sylilzy/g", "g1");
    o=ctx2.lookup("g1");
    System.out.println("get object from jndi:"+o);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

Results:
-- listing properties --
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Got context
get object from jndi:I am sily a!
get object from jndi:this is g
程序中jbossJndi.properties文件的内容为:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099

上述示例程序在jboss服务器的jndi树上建立了几个上下文,并bind了几对象,
结果为:
-----------------------------
/sylilzy/sily
-----------------------------
/sylilzy/sily/b:I am sily b!
/sylilzy/sily/a:I am sily a!
/sylilzy/sily/g1:this is g
-----------------------------
分享到:
评论

相关推荐

    Apache Geronimo 2.1_ Quick Reference.pdf

    Accessing the sample app through Apache web server 315 Running multiple server instances from a single installation 315 Clustered Helloworld-cluster application 317 Updating workers.properties 317...

    JDBC Developers Guide Reference.rar

    (and their usage of JNDI), connection pooling functionality (a framework for connection caching implementations), and a sample connection caching implementation provided by Oracle. Chapter 16, ...

    android 多任务的多线程断点续传的下载软件

    更多代码在 https://gitee.com/drip_on/ldown_sample.git * ldown是一款跨平台多任务的多线程断点续传的下载软件, * 支持 HTTP / FTP / BT / Magnet 磁力链接等类型的文件下载;支持 Win、android、Linux系统。 * ...

    hibernate.properties

    ## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI ## default is java:comp/UserTransaction ## you do NOT need this setting if you specify hibernate....

    Java.EE.7.Essentials

    Walkthrough of a Sample Application Show Booking (JavaServer Faces) Chat Room (Java API for WebSocket) View and Delete Movies (Java API for RESTful Web Services) Add Movie (Java API for JSON ...

    BlazeDS开发者指南

    Running the BlazeDS sample applications 14 Building your client-side application 15 Building your server-side application 20 Debugging your application 22 Deploying your application 25 Part 2: BlazeDS...

    ibatis 开发指南(pdf)

    ibatis 开发指南 ibatis Quick Start............................................................................................ 5 准备工作.................//iBATIS.com//DTD SQL Map Config 2.0//EN"<br>"http://www.ibatis.com/dtd/sql-map-config-2.dtd"><br><sqlMapConfig><br><settings<br>cacheModelsEnabled="true"<br>enhancementEnabled="true"<br>lazyLoadingEnabled="true"<br>errorTracingEnabled="true"<br>maxRequests="32"<br>maxSessions="10"<br>maxTransactions="5"<br>useStatementNamespaces="false" <br>/><br><transactionManager type="JDBC"><br><br><dataSource type="SIMPLE"> <br><property name="JDBC.Driver" <br>value="com.p6spy.engine.spy.P6SpyDriver"/> <br><property name="JDBC.ConnectionURL" <br>value="jdbc:mysql://localhost/sample"/> <br><property name="JDBC.Username" ="user"/> <br><property name="JDBC.Password" ="mypass"/> <br><property name=<br>value="10"/> <br><property name=value="5"/> <br><property name=<br>value="120000"/> <br><property name="Pool.TimeToWait" ="500"/> <br><property name="Pool.PingQuery" ="select 1 from <br>ACCOUNT"/> <br><property name="Pool.PingEnabled" ="false"/> <br><property name=<br>value=...

    java7帮助文档

    Libraries IDL JDBC JNDI RMI RMI-IIOP Scripting Other Base Libraries Beans Int'l Support Input/Output JMX JNI Math Networking Override Mechanism Security Serialization Extension Mechanism XML JAXP ...

    JSP2.0技术手册pdf(带示例源码).zip

    2-2 First Servlet Sample Code 2-3 Servlet 的生命周期 2-4 Servlet 范例程序 2-5 Servlet 2.4 的新功能 第三章 JSP 2.0 简介 3-1 JavaServer Pages 技术 3-2 What is JSP 3-3 JSP 与 Servlet 的比较 3-4 JSP 的...

    JavaSE-6.0-英文手册(2008/11/30_FullUpdate)

    Java Naming and Directory InterfaceTM (JNDI) Remote Method Invocation (RMI) RMI-IIOP Scripting for the Java Platform User Interface Libraries 2D Graphics and Imaging Accessibility ...

    java.核心技术.第八版 卷1

    All sample programs have been carefully crafted to illustrate the latest programming techniques, displaying best-practices solutions to the types of real-world problems professional developers ...

    ORACLE OSB开发指南

    Creating and Editing JNDI Provider Resources ............................................................................ 2-4 Creating Proxy Server Resources..............................................

Global site tag (gtag.js) - Google Analytics