【问题标题】:How to override resource-ref in WildFly如何在 WildFly 中覆盖资源引用
【发布时间】:2017-05-06 15:12:00
【问题描述】:

在我的application.xml 中,我有以下内容:

<resource-ref>
<res-ref-name>java:app/ds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

在 WebSphere 上,它允许我覆盖它以匹配部署期间容器中可用的任何内容。但是,在需要在 XML 文件中解析数据的 WildFly 中,我在 jboss-app.xml 中找不到功能,http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd 中没有定义任何内容以允许更改资源引用

【问题讨论】:

    标签: jakarta-ee jboss wildfly


    【解决方案1】:

    这在JBoss Deployment Descriptors 中没有明确记录,但我找到了一个示例,它确实有效。

    对于application.xml,需要添加lookup-name

    <resource-ref>
    <res-ref-name>java:app/ds</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <lookup-name>java:app/ds</lookup-name>
    </resource-ref>
    
    EAR 中的

    META-INF/jboss-app.xml 将如下所示(注意命名空间和模式):

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss:jboss-app 
      xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
      xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" 
      version="7">
      <resource-ref>
        <res-ref-name>java:app/ds</res-ref-name>
        <lookup-name>java:/PacDB</lookup-name>
      </resource-ref>
    </jboss:jboss-app>
    

    不幸的是,WildFly 在 CDI https://issues.jboss.org/browse/JBAS-8818 方面存在更多基本问题,使我无法实际进行部署。但是你可以看到它确实从这个项目中正确加载了https://github.com/trajano/jee/tree/for-JBAS-8818

    【讨论】:

      【解决方案2】:

      resource-ref 在 web.xml 中定义,例如使用 JavaEE Servlet 3 查找名称来指定全局 jndi 名称:

      <web-app xmlns="http://java.sun.com/xml/ns/javaee";
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";
               version="3.0">
      
           ...
      
          <!-- JDBC DataSources (java:comp/env/jdbc) -->
          <resource-ref>
              <description>The default DS</description>
              <res-ref-name>jdbc/myDS</res-ref-name> <!-- this must match the res-ref-name in the jboss-web.xml -->
              <res-type>javax.sql.DataSource</res-type>
              <res-auth>Container</res-auth>
              <lookup-name>java:jboss/datasources/ExampleDS</lookup-name>
          </resource-ref>
      

      因此,在 EAR 中,您应该在 Web 应用程序中执行此操作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-31
        • 1970-01-01
        • 2013-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多