你好papapa,感谢你的好意。
说来惭愧,你的问题我还是没能帮你解决,希望你重装了Weblogic就行了,到时一定通知小弟一声。在讨论问题的同时,还能结识志朋友真是令人快慰。希望我们能共同学习和进步。我的QQ:22908570
我的问题其实是:在Web.xml中定义了
<resource-ref>
    <res-ref-name>jdbc/ProductDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
但不知如何与Weblogic的Console中的DataSource联系起来。
后来在petstore中发现它的<resource-ref>是在sun-j2ee-ri.xml中指定的。
<resource-ref>
      <res-ref-name>jdbc/CatalogDB</res-ref-name>
      <jndi-name>jdbc/petstore/PetStoreDB</jndi-name>
      <default-resource-principal>
        <name>estoreuser</name>
        <password>estore</password>
      </default-resource-principal>
</resource-ref>
同时sun-j2ee-ri.xml是放在???.ear中的META-INF中的,我试了一下还是不行。
部署时就报错,“找不到jdbc/ProductDB指定的资源”我想自己在试试,找一些文档看看,如还是不行就发个贴子请高手指点。

解决方案 »

  1.   

    你的问题的全威解答在
    http://e-docs.bea.com/wls/docs70/webapp/components.html#100650
    Referencing EJBs in a Web ApplicationEJBs that you use in a Web Application can be deployed either externally to the application, or deployed within the scope of the Web Application as part of an EAR file. The procedures for referencing an EJB differ depending on whether the EJB is external or application-scoped.Referencing External EJBs(用Jndi的方法)Web Applications can access EJBs that are deployed as part of a different application (a different EAR file) by using an external reference. The EJB being referenced exports a name to the global JNDI tree in its weblogic-ejb-jar.xml deployment descriptor. An EJB reference in the Web Application module can be linked to this global JNDI name by adding an <ejb-reference-description> element to its weblogic.xml deployment descriptor.This procedure provides a level of indirection between the Web Application and an EJB and is useful if you are using third-party EJBs or Web Applications and cannot modify the code to directly call an EJB. In most situations, you can call the EJB directly without using this indirection. For more information, see Invoking Deployed EJBs.To reference an external EJB for use in a Web Application:
    Enter the EJB reference name you use to look up the EJB in your code, the Java class name, and the class name of the home and remote interfaces of the EJB in the <ejb-ref> element of the Web Application deployment descriptor. For instructions on making deployment descriptor entries, see Step 21: Reference Enterprise JavaBean (EJB) resources Map the reference name in <ejb-reference-description> element of the WebLogic-specific deployment descriptor, weblogic.xml, to the JNDI name defined in the weblogic-ejb-jar.xml file. For instructions on making deployment descriptor entries, see Step 3 Map resources to JNDI.
    If the Web Application is part of an Enterprise Application Archive (.ear file), you can reference an EJB by the name used in the .ear with the <ejb-link> element.Referencing Application-Scoped EJBs(用类装载器)Within an application, WebLogic Server binds any EJBs referenced by other application components to the environments associated with those referencing components. These resources are accessed at runtime through a JNDI name lookup relative to java:comp/env.The following is an example of an application deployment descriptor (application.xml) for an application containing an EJB and a Web Application. (The XML header is not included for brevity.)Listing 3-6 Example Deployment Descriptor  <application>
         <display-name>MyApp</display-name>
         <module>
            <web>
               <web-uri>myapp.war</web-uri>
               <context-root>myapp</context-root>
            </web>
         </module>
         <module>
            <ejb>ejb1.jar</ejb>
         </module>
      </application>
    To allow the code in the Web application to use an EBJ in ejb1.jar, the Web application deployment descriptor (web.xml) must include an <ejb-ref> stanza that contains an <ejb-link> referencing the JAR file and the name of the EJB that is being called.The format of the <ejb-link> entry must be as follows:filename#ejbname 
    where filename is the name of the JAR file, relative to the Web application, and ejbname is the EJB within that JAR file. The <ejb-link> element should look like the following:<ejb-link>../ejb1.jar#myejb</ejb-link>
    Note that since the JAR path is relative to the WAR file, it begins with "../". Also, if the ejbname is unique across the application, the JAR path may be dropped. As a result, your entry may look like the following:<ejb-link>myejb</ejb-link>
    The <ejb-link> element is a sub-element of an <ejb-ref> element contained in the Web application's web.xml descriptor. The <ejb-ref> element should look like the following:Listing 3-7 <ejb-ref> Element <web-app>
       ...
       <ejb-ref>
          <ejb-ref-name>ejb1</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          <home>mypackage.ejb1.MyHome</home>
          <remote>mypackage.ejb1.MyRemote</remote>
          <ejb-link>../ejb1.jar#myejb</ejb-link>
       </ejb-ref>
       ...
     </web-app>
    The name referenced in the <ejb-link> (in this example, myejb) corresponds to the <ejb-name> element of the referenced EJB's descriptor. As a result, the deployment descriptor (ejb-jar.xml) of the EJB module that this <ejb-ref> is referencing should have an entry an entry similar to the following:Listing 3-8  <ejb-jar>
       ...
       <enterprise-beans>
          <session>
             <ejb-name>myejb</ejb-name>
             <home>mypackage.ejb1.MyHome</home>
             <remote>mypackage.ejb1.MyRemote</remote>
             <ejb-class>mypackage.ejb1.MyBean</ejb-class>
             <session-type>Stateless</session-type>
             <transaction-type>Container</transaction-type>
          </session>
       </enterprise-beans>
       ...
     </ejb-jar>
    Notice the <ejb-name> element is set to myejb. Note: For more instructions on creating deployment descriptor entries, see Step 21: Reference Enterprise JavaBean (EJB) resources.At runtime, the Web Application code looks up the EJB's JNDI name relative to java:/comp/env. The following is an example of the servlet code:MyHome home = (MyHome)ctx.lookup("java:/comp/env/ejb1");
    The name used in this example (ejb1) is the <ejb-ref-name> defined in the <ejb-ref> element of the web.xml segment above.
      

  2.   

    我的问题在bea上也找到答案了。Configuring Resources in a Web ApplicationThe resources that you use in a Web Application are generally deployed externally to the application. JDBC Datasources can optionally be deployed within the scope of the Web Application as part of an EAR file.Prior to WebLogic Server 7.0, JDBC DataSources were always deployed externally to the Web Application. To use external resources in the Web Application, you resolve the JNDI resource name that the application uses with the global JNDI resource name using the web.xml and weblogic.xml deployment descriptors. See Configuring External Resources for more information.WebLogic Server 7.0 enables you deploy JDBC DataSources as part of the Web Application EAR file by configuring those resources in the weblogic-application.xml deployment descriptor. Resources deployed as part of the EAR file are referred to as application-scoped resources. These resources remain private to the Web Application, and application components can access the resource names directly from the local JNDI tree at java:comp/env. See Configuring Application-Scoped Resources for more information.Configuring External ResourcesWhen accessing external resources (resources not deployed with the application EAR file) such as a DataSource from a Web Application via Java Naming and Directory Interface (JNDI), you can map the JNDI name you look up in your code to the actual JNDI name as bound in the global JNDI tree. This mapping is made using both the web.xml and weblogic.xml deployment descriptors and allows you to change these resources without changing your application code. You provide a name that is used in your Java code, the name of the resource as bound in the JNDI tree, and the Java type of the resource, and you indicate whether security for the resource is handled programmatically by the servlet or from the credentials associated with the HTTP request. To configure external resources:
    Enter the resource name in the deployment descriptor as you use it in your code, the Java type, and the security authorization type. For instructions on making deployment descriptor entries, see Step 16: Reference external resources. Map the resource name to the JNDI name. For instructions on making deployment descriptor entries, see Step 3 Map resources to JNDI.
    This example assumes that you have defined a data source called accountDataSource. For more information, see JDBC Data Sources.Listing 3-4 Example of Using an External DataSourceServlet code: javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup                           ("myDataSource");
    web.xml entries:
    <resource-ref>. . .   <res-ref-name>myDataSource</res-ref-name>   <res-type>javax.sql.DataSource</res-type>   <res-auth>CONTAINER</res-auth>. . .</resource-ref>
    weblogic.xml entries:
    <resource-description>   <res-ref-name>myDataSource</res-ref-name>   <jndi-name>accountDataSource</jndi-name></resource-description>
    Configuring Application-Scoped ResourcesWebLogic Server binds application-scoped resource names to the application's local JNDI tree. The Web Application code accesses these resources by looking up the actual JNDI resource name relative to java:comp/env.If your Web Application uses only application-scoped resources, you do not need to enter global JNDI resources names in the weblogic.xml deployment descriptor, as described in Configuring External Resources. (In fact, you can omit weblogic.xml entirely if you do not require any other features of that deployment descriptor.)To configure application-scoped resources:
    Enter the resource definition in the weblogic-application.xml deployment descriptor. See weblogic-application.xml Deployment Descriptor Elements in Developing WebLogic Server Applications for more information. Ensure that Web Application code uses the same JNDI name specified in weblogic-application.xml, and that it references the name relative to the local JNDI tree at java:comp/env. 
    Note: If Web Application code uses a different JNDI name to reference the resource, you must treat the resource as external and configure the weblogic.xml deployment descriptor as describe in the next section.Listing 3-5 Example of Using an External DataSourceServlet code: javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup                           ("java:comp/env/myDataSource");
    weblogic-application.xml entries:
    <weblogic-application>   <data-source-name>myDataSource</data-source-name></weblogic-application>
      

  3.   

    因周末没有地方上网,来迟了,请原谅!能够交到你这样好心的朋友,真是幸运,我的QQ是:199602655,有事联系啊我刚才测试了一下你上面提到的方法,如果weblogic.xml不定义,部署都有问题,可能是我的weblogic有问题。不过我因有新的任务,可能没时间仔细研究了,也没时间重装了。以后若有机会搞清楚原理,一定详细向你汇报。恭喜你啊找到答案了。