jndi.properties文件配置信息

package test;

import javax.naming.Context;
import javax.naming.InitialContext;

public class JNDIDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
//	    	   Properties pro = new Properties();
//	    	   pro.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
//			   pro.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces ");
//			   pro.put(Context.PROVIDER_URL, "localhost:1099"); 

//	    	   Context ctx = new InitialContext(pro);
	    	   Context ctx = new InitialContext();
	    	   System.out.println(1);
	    	   ctx.bind("username", "zhangsan");
	    	   System.out.println(2);
//	    	   ctx.rebind("username", "liuliu");
//	    	   ctx.unbind("username");
	    	   String name = (String)ctx.lookup("username");
	    	   System.out.println(3);
	    	   System.out.println(name);
	    	   System.out.println(4);
	       }
	       catch (Exception e) {
	    	    e.printStackTrace();
	    	    }
	}

}
发布了143 篇原创文章 · 获赞 11 · 访问量 8208

猜你喜欢

转载自blog.csdn.net/weixin_43701790/article/details/103433558
今日推荐