欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Java技術(shù)回顧之JNDI(二):JNDI應用實(shí)例,Java技術(shù)文章,Java系列教程,Java

♦日志服務(wù)對象工廠(chǎng)類(lèi) SimpleLogServiceFactory.java

package xyz.serviceprovider;

import java.util.Hashtable;

import javax.naming.Context;
importjavax.naming.Name;
import javax.naming.Reference;
importjavax.naming.spi.ObjectFactory;

public class SimpleLogServiceFactory implementsObjectFactory {

 publicObject getObjectInstance(Object obj, Name name, Context ctx,
   Hashtable<?,?> env) throws Exception {
  if(obj instanceof Reference){
   returnnew SimpleLogService();
  }
  return null;
 }
}

 4、JNDI容器和JNDI客戶(hù)端
最后,我們在JNDI應用package(xyz.jndi)中實(shí)現一個(gè)JNDI容器JNDIContainer和一個(gè)JNDI客戶(hù)端應用JNDIClient。
JNDIContainer在內部使用文件系統服務(wù)提供者fscontext來(lái)提供命名和目錄服務(wù),配置文件JNDIContainer.properties是服務(wù)注入場(chǎng)所,供配置DBService和LogService實(shí)現。

♦JNDI容器類(lèi) JNDIContainer.java

package xyz.jndi;

import java.io.InputStream;
importjava.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
importjavax.naming.InitialContext;
import javax.naming.NamingException;

import xyz.service.DBService;
importxyz.service.LogService;

publicclass JNDIContainer {

 privateContext ctx=null;
 
 public void init() throws Exception{
    //初始化JNDI提供者。
     Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, "file:/c:/sample");//fscontext的初始目錄,我們需要在c:\下創(chuàng )建sample目錄。
     ctx=newInitialContext(env);
     loadServices();
 }
 
 //從配置文件JNDIContainer.properties中讀取DBService和LogService實(shí)現,綁定到Context中。
 privatevoid loadServices() throws Exception{
  InputStreamin=getClass().getResourceAsStream("JNDIContainer.properties");
  Propertiesprops=new Properties();
  props.load(in);
  
  //injectdbservice
  String s=props.getProperty("DBServiceClass");
  Objectobj=Class.forName(s).newInstance();
  if(obj instanceof DBService){
   DBServicedb=(DBService)obj;
   String[]ss=props.getProperty("DBServiceProperty").split(";");
   for(inti=0;i<ss.length;i++)
    db.setProperty(i, ss[i]);
   ctx.rebind(props.getProperty("DBServiceName"),db);
  }
  
  //inject logservice
  s=props.getProperty("LogServiceClass");
  obj=Class.forName(s).newInstance();
  if(objinstanceof LogService){
   LogService log=(LogService)obj;
   ctx.rebind(props.getProperty("LogServiceName"),log);
  }
 }
 
 public void close() throws NamingException{
  ctx.close();
 }
 
 publicContext getContext(){
  return ctx;
 }
}

♦JNDI容器配置文件 JNDIContainer.properties

//和JNDIContainer.java文件位于同一目錄
DBServiceName=DBService
DBServiceClass=xyz.serviceprovider.SimpleDBService
DBServiceProperty=mydb//192.168.1.2:8421/testdb;start

LogServiceName=LogService
LogServiceClass=xyz.serviceprovider.SimpleLogService

♦JNDI客戶(hù)端 JNDIClient.java

packagexyz.jndi;

importjavax.naming.Context;

importxyz.service.DBService;
import xyz.service.LogService;

public class JNDIClient {
 
 publicstatic void main(String[] args){
  try{
   JNDIContainercontainer=new JNDIContainer();
   container.init();
   
     //JNDI客戶(hù)端使用標準JNDI接口訪(fǎng)問(wèn)命名服務(wù)。
      Context ctx=container.getContext();
     DBService db=(DBService)ctx.lookup("DBService");
     System.out.println("db location is:"+db.getLocation()+",stateis:"+db.getState());
      db.accessDB();
     
     LogService ls=(LogService)ctx.lookup("LogService");
     ls.log("this is a log message.");
     
      container.close();
  }
  catch(Exceptione){
   e.printStackTrace();
  }
 }
}

至此,我們的整個(gè)Java SE應用已經(jīng)完成。下面是整個(gè)應用的源代碼結構(Eclipse工程):

 

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
開(kāi)發(fā)基于JNDI的應用程序
JNDI配置原理詳解(轉)- 高山流水 - 新浪BLOG
jndi和rmi的集成。
J2EE中的JNDI服務(wù)介紹
搭建JNDI應用環(huán)境并試驗JDNI
JNDI 學(xué)習
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久