在Glassfish 4.1.1自定义资源上进行JNDI查找 [英] JNDI lookup on Glassfish 4.1.1 custom resources

查看:162
本文介绍了在Glassfish 4.1.1自定义资源上进行JNDI查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JNDI自定义资源直接在我的服务器(Glassfish)中存储数据,但它显然无法正常工作。

I am trying to use JNDI custom resources to store data directly in my server (Glassfish) but it is apparently not working.

我将JNDI定义为下面的图片

I define my JNDI as on the image below

,对应于以下说明在我的domain.xml中。

which corresponds to the following description in 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中获取此值。

And then, i am trying to get this value in one of my managed bean.

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

但是...... javax.naming.NamingException:'projectStage查找失败'是我唯一得到的。

But... javax.naming.NamingException: Lookup failed for 'projectStage' is the only thing i get from it.

如果有人对我有所了解,我会很感激!

If anyone has an idea for me, i will be thankful !

推荐答案

解决了!

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

I was editing my domain.xml manually to add my JNDI custom resource as Glassfish 4.1.1 administration interface gives an Runtime error when clicking on New... on the JNDI Custom Resource section.

编辑完 domain.xml 文件后,显示在管理面板中,但显然没有正常工作。

Once the domain.xml file edited, it was displayed well in the administration panel but apparently not properly working.

我用 create-custom-resource asadmin控制台的命令解释此处

I have created the custom resource with the create-custom-resource command of the asadmin console explains here.

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

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

And then it looks to be properly added to the system. (looks like it is not only stored in the domain.xml file)

这篇关于在Glassfish 4.1.1自定义资源上进行JNDI查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆