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

glassfish 4.1.1自定义资源的jndi查找

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

    我正试图使用jndi自定义资源直接在我的服务器(glassfish)中存储数据,但显然不起作用。

    我的jndi定义如下

    enter image description here

    对应于my domain.xml中的以下描述。

    <custom-resource factory-class="org.glassfish.resources.custom.factory.PrimitivesAndStringFactory" res-type="java.lang.String" jndi-name="projectStage">
          <property name="value" value="UnitTest"></property>
    </custom-resource>
    

    然后,我试图在我的一个托管bean中获取这个值。

    Context c = new InitialContext();
    c.lookup("projectStage");
    

    但是… javax.naming.NamingException: Lookup failed for 'projectStage' 是我从中得到的唯一东西。

    如果有人对我有想法,我会感激的!

    2 回复  |  直到 6 年前
        1
  •  0
  •   robinvrd    6 年前

    解决了的!

    我正在手动编辑domain.xml以添加jndi自定义资源,因为glassfish 4.1.1管理界面在单击时会出现运行时错误 新建… 在jndi自定义资源部分。

    一旦 domain.xml 文件编辑后,它在管理面板中显示良好,但显然无法正常工作。

    我已经用 create-custom-resource asadmin控制台的命令解释 here 是的。

    create-custom-resource --restype java.lang.String --factoryclass org.glassfish.resources.custom.factory.PrimitivesAndStringFactory --property "value=UnitTest" projectStage
    

    然后它看起来被正确地添加到系统中。(看起来它不仅存储在 域.xml 文件)

        2
  •  0
  •   Per Westling    6 年前

    在旧的glassfish版本和glassfish 4.1之间手动传输配置时,我遇到了类似的问题。

    你建议的解决方案确实有效,但是如果你有很多属性的话,那就需要做很多工作。但是通过 阿斯丁 和比较 域.xml 我找到了失败的原因。

    如果你加上 自定义资源 玻璃鱼找不到它。它还需要有对资源的引用。 在我的情况下是在 <服务器> 部分,需要一个

    <resource ref ref=“项目阶段”></resourceref>