`
dev_liu
  • 浏览: 110997 次
  • 性别: Icon_minigender_1
  • 来自: 成都
最近访客 更多访客>>
社区版块
存档分类
最新评论

我走了弯路!

    博客分类:
  • JNDI
阅读更多

 

今天尝试了一下初始化上下文目录.下面简单的代码就可以代替以下那么多代码和配置文件哎..自己走了弯路呀.

Properties pr =new Properties();
  pr.put("82.0.176.214","16400");
  javax.naming.Context  ictx = new InitialContext(pr);

 

 

 

 

烦琐的代码..和配置文件....不过路是一步一步走的....

javax.naming.Context  ictx = new InitialContext(JMSConstant.getProp());

写个类去获取jndi.properties的内容

public class JMSConstant {
 /**
  * jndi.properties
  */
 private static Properties prop = null;
 /**
  * 获得Server.properties实例
  * @return properties
  */
 public static Properties getProp(){
  if(prop == null){
   prop = new Properties();
   try {   
    prop.load(JMSConstant.class.getResourceAsStream("/jndi.properties"));
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  return prop;
 }
}

jndi.properties=======>>>>>>

#jndi parameters
java.naming.factory.initial=fr.dyade.aaa.jndi2.client.NamingContextFactory
java.naming.factory.host 82.0.176.214
java.naming.factory.port 16400

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics