代码经常看到通过JNDI找一个自定义服务名称,类似使用JDBC一样通过JNDI找到后使用,在JBOSS环境中这样做法是不是更高效?是不是我自己先开发一个普通的jar包部署到jboss环境中,然后再配置文件中注册其JNDI名字,jboss其起来后,在代码中通过查找jndi方式找到并使用? 为什么EJB可以呢

解决方案 »

  1.   

    ,JNDI效率还行,Java很多东西是不考虑效率的。
      

  2.   

    jndi用途一般是查找数据源 
    访问容器的ejb,性能不错
    你当然可以注册然后在代码中查找
    但是没有必要...自己直接引用性能才高
      

  3.   

    谢谢,项目中EJB也是使用jndi的查找方式,一些中间件它一般也提供了jndi获取其服务的方式,那其实不一定要用jndi的咯?
    下午马上结贴
      

  4.   

    名称与实体关联,貌似就是为了便利,可能效率上有些差别或者...看维基也没看出到底适用性或必要性在哪The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and objects via a name. Like all Java APIs that interface with host systems, JNDI is independent of the underlying implementation. Additionally, it specifies a service provider interface (SPI) that allows directory service implementations to be plugged into the framework. It may make use of a server, a flat file, or a database; the choice is up to the vendor.感觉就是一种解耦