mr923 发表于 2017-5-25 07:04:35

IBM WebsPhere Jndi数据源

引用

websphere 下获取jndi,java:comp/env/cas与jdbc/cas的区别:
    A.lookup("java:comp/env/cas")与lockup("jdbc/cas")在websphere中都可以使用。两者的差别在于,java:comp/env/cas是websphere建议使用的方式
    如果你当前的线程属于websphere的线程,建议使用java:comp/env/cas的方式,否则was的控制台将报出警告。
      在web程序中,要实现通过java:comp/env/cas的方式来获得jndi必须在web.xm和ibm-web-bnd.xmi文件里分别添加
      web.xml:
      <resource-ref    id="ResourceRef_1129470735234">   
         <res-ref-name>cas_ase</res-ref-name>   
         <res-type>java.sql.DataSource</res-type>   
         <res-auth>Container</res-auth>   
         <res-sharing-scope>Shareable</res-sharing-scope>   
      </resource-ref>
      ibm-web-bnd.xmi:
      <resRefBindings    xmi:id="ResourceRefBinding_1129470735234"    jndiName="jdbc/cas_ase">   
         <bindingResourceRef    href="WEB-INF/web.xml#ResourceRef_1129470735234"/>   
      </resRefBindings>
      以上两段配置的意思是告诉web容器的上下文环境,将应用映射到的jndi资源。然后就可以通过lookup(“java:comp/env/cas/jdbc/cas_ase”)名来获得数据源。
   然而,如果你当前执行的线程不在was的容器内,比如说你通过web容器的线程新起了一个子线程,那么该线程将不在容器的上下文内,通过lookup(“java:comp/env/cas/jdbc/cas_ase”)名来获得数据源
   将报错,这个时候你只能使用通用的获取jndi资源的方式,就是通过lookup(“jdbc/cas”)来实现。“jdbc/cas”为你在was的资源设定的jndi名.
页: [1]
查看完整版本: IBM WebsPhere Jndi数据源