你好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指定的资源”我想自己在试试,找一些文档看看,如还是不行就发个贴子请高手指点。
说来惭愧,你的问题我还是没能帮你解决,希望你重装了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指定的资源”我想自己在试试,找一些文档看看,如还是不行就发个贴子请高手指点。
解决方案 »
- JSF 2.0 中文版的各种资料啊~~
- S2SH整合hibernate使用注解问题
- hibernate3 属性 延迟加载 中的问题,请大家有知道的帮帮忙,谢谢。
- 求一个hibernate映射用注释写的多表级联保存例子
- 如何向数据库中保存既有图片又有文字的内容
- 如何运行jar文件?
- 数据连接池的问题
- 第一次来这里,请教问题 The Network Adapter could not establish the conn
- J2EE多层技术应用开发调查。up者有分!!!!
- struts项目,tomcat报错,帮帮我好吗?
- 多个CMP对一个SessionBean好,还是一个CMP对一个SessionBean好?
- j2ee应该怎么学起!
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.
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>