`

Websphere报不推荐使用jndi资源名警告的解决办法

 
阅读更多

[07-12-4 11:17:51:921 CST] 0000001a ConnectionFac W   J2CA0294W: 不推荐使用资源 jdbc/oracleDS 的直接 JNDI 查找。使用下列缺省值:[Resource-ref settings]

res-auth:                 1 (APPLICATION)
res-isolation-level:      0 (TRANSACTION_NONE)
res-sharing-scope:        true (SHAREABLE)
loginConfigurationName:   null
loginConfigProperties:    null
[Other attributes]

res-resolution-control:   999 (undefined)
res ref or CMP bean name: null
Database pool properties: null
primeID:                  0
isCMP1_x:                 false (not CMP1.x)
isJMS:                 false (not JMS)

##########################################################################################

解决方法:WebSphere Application Server 6.1.0.0 下:

\WEB-INF\ibm-web-bnd.xmi文件

<?xml version="1.0" encoding="UTF-8"?>
<com.ibm.ejs.models.base.bindings.webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:com.ibm.ejs.models.base.bindings.webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1196672221187" virtualHostName="default_host">

<webapp href="WEB-INF/web.xml#WebApp_1166165893137"/>

<resRefBindings xmi:id="ResourceRefBinding_2" jndiName="jdbc/oracleDS">
    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_2"/>
</resRefBindings>

</com.ibm.ejs.models.base.bindings.webappbnd:WebAppBinding>


\WEB-INF\web.xml文件 资源引用

<resource-ref id="ResourceRef_2">
      <res-ref-name>jdbc/sxidc</res-ref-name>
      <res-type>java.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

以上配置将配置在websphere中的数据源 jdbc/oracleDS 映射为 jdbc/sxidc的间接名称。数据源的获取用如下的jndi   java:comp/env/jdbc/sxidc


如代码“InitialContext initCtx = new InitialContext();
         Context envCtx = (Context) initCtx.lookup("");
         ds = (DataSource) envCtx.lookup("java:comp/env/jdbc/sxidc");
         connection = ds.getConnection();”


或如hibernate配置文件中

      <session-factory>
   <property name="hibernate.connection.datasource">
    java:comp/env/jdbc/sxidc
   </property>
      ........................


#######################################
较早的版本中 j2ee1.3 ....

ibm-web-bnd.xml 中有这段内容,这个将会再部署到 WAS 时自动被管理控制台读出来并创建资源配置,跟我们手工创建一个数据源一样。
<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1" virtualHostName="default_host">
   <webapp href="WEB-INF/web.xml#WebApp"/>

   <resRefBindings xmi:id="ResourceRefBinding_1129470735234" jndiName="jdbc/xa/sample">
     <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1129470735234"/>
   </resRefBindings>

</webappbnd:WebAppBinding>

下面这个是 web.xml 中的一段内容,这里 id 和上面的 ref 对应,这样就能映射一个 全局 资源到一个 web容器组件内的资源上来。 资源是配置在服务器的全局资源池中他的 JNDI 为 jdbc/xa/sample, 然后映射到 web 容器这个组件中名字为jdbc/sample.我用 ctx.lookup("java:comp/env/jdbc/sample") 来访问,因为你   ctx.lookup("java:comp/env/xxxx") 时就是在web容器内,在ejb 中调用 ctx.lookup("java:comp/env/xxxx")   则是在 ejb 容器内的,如果没有配置引用你可能找不到资源,或者导致一个上面的警告, Tomcat 5 中没有 ibm-web-bnd.xml ,但是 Tomcat 5 能在一个 context 的配置中添加一个 resource-link 来完成这个映射,方法是在 /META-INF/ 中的context.xml (如果没有这个文件,可以从 %CATALINA_HOME%/conf/Catalina/localhost/manager.xml 拷贝一个,改一下内容,并改名为 context.xml ),在其中添加一个resource-link . 具体操作也可以 jakarta.apache.org/tomcat 下载一个 jakarta-tomcat-admin-x.xx.zip 并解压,用它来完成配置。

<web-app>
<!--   ... 其他内容省略 -->

<resource-ref id="ResourceRef_1129470735234">
    <res-ref-name>jdbc/sample</res-ref-name>
    <res-type>java.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

</web-app>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics