代码之家  ›  专栏  ›  技术社区  ›  robinvrd

在Glassfish 4.1上使用JNDI设置项目阶段

  •  1
  • robinvrd  · 技术社区  · 7 年前

    我正在寻找在Glassfish(v4.1.1 build 1)上使用JNDI配置设置项目阶段,以允许我的服务器拥有每个不同的项目阶段,并允许我在不更改javax的情况下使用Git进行修改。面孔。PROJECT\u阶段在web中。每次推送时使用xml。

    我已经试过了 this post 但它似乎不起作用,可能是因为它与Glassfish版本不同。

    在web中。xml(在我的项目中)

    <resource-ref>
        <res-ref-name>jsf/ProjectStage</res-ref-name>
        <res-type>java.lang.String</res-type>
        <mapped-name>javax.faces.PROJECT_STAGE</mapped-name>
    </resource-ref>
    

    在域中。xml(我的服务器使用的域)

    <custom-resource factory-class="com.sun.faces.application.ProjectStageJndiFactory" res-type="java.lang.String" jndi-name="javax.faces.PROJECT_STAGE">
        <property name="stage" value="Development"></property>
    </custom-resource>
    

    我也试过 <property name="value" value="Development"></property> 而不是 name="stage" .

    但是,当我展示 #{facesContext.application.projectStage} ,它显示为 Production 因为它看起来是默认阶段。

    希望你能帮助我,谢谢!

    1 回复  |  直到 7 年前
        1
  •  1
  •   robinvrd    6 年前

    解决了我的问题!

    在手动编辑 domain.xml 文件没有像我解释的那样正确创建资源 here .

    因此,它可以与使用asadmin命令创建的JNDI自定义资源正常工作。

    JNDI自定义资源创建命令

    create-custom-resource --restype java.lang.String --factoryclass com.sun.faces.application.ProjectStageJndiFactory --property "stage=Development" javax.faces.PROJECT_STAGE
    

    网状物xml

    <resource-ref>
        <res-ref-name>jsf/ProjectStage</res-ref-name>
        <res-type>java.lang.String</res-type>
        <mapped-name>javax.faces.PROJECT_STAGE</mapped-name>
    </resource-ref>