我正在尝试使用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查找
发布评论