获取并设置;来自远程客户端
我有带有远程接口 TimeService 的 EJB TimeServiceEJB。在我的 EJB 模块的部署描述符中,有:
<ejb-name>TimeServiceEJB</ejb-name>
...
<env-entry>
<description>... </description>
<env-entry-name>variable</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>10</env-entry-value>
</env-entry>
我需要从客户端应用程序获取此变量并能够对其进行编辑。我试图这样做:
Properties p = new Properties();
p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
p.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext iniCtx = new InitialContext(p);
Integer variable = (Integer) iniCtx.lookup("java:comp/ejb/TimeServiceEJB/variable");
但我什么也没得到。尝试以不同的方式查找(“java:global/ejb/TimeServiceEJB/variable”、“java:comp/env/TimeServiceEJB/variable”、“java:global/ear-name/module-name/TimeServiceEJB/) - 总是有“javax.naming.NameNotFoundException:没有对象绑定...”
尝试通过注释@Resource(name =“variable”, mappedName="env/variable"),并通过“env/variable”查找,但得到了 NameNotFoundException。
有什么想法,如何获取这个变量吗?第二个问题是:我可以编辑它的值吗?
I have EJB TimeServiceEJB with remote interfce TimeService. In Deploy descriptor of my EJB module there is:
<ejb-name>TimeServiceEJB</ejb-name>
...
<env-entry>
<description>... </description>
<env-entry-name>variable</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>10</env-entry-value>
</env-entry>
I need to get this variable from client application and be able to edit it. I trying to do it this way:
Properties p = new Properties();
p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
p.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext iniCtx = new InitialContext(p);
Integer variable = (Integer) iniCtx.lookup("java:comp/ejb/TimeServiceEJB/variable");
But i got nothing. Tried to lookup in different ways ("java:global/ejb/TimeServiceEJB/variable", "java:comp/env/TimeServiceEJB/variable", "java:global/ear-name/module-name/TimeServiceEJB/) - always had "javax.naming.NameNotFoundException: No object bound for ..."
Tried to set mappingName of this variable by annotaion @Resource(name="variable", mappedName="env/variable"), and lookup by "env/variable", but got NameNotFoundException.
Is there any ideas, how to get this variable? And the second question is: can i edit its value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
环境条目仅在应用程序组件的命名上下文中可见(即声明它的 EJB 或 Web 模块内的
InitialContext
中的java:comp/env
)。 (例外:Java EE 6 提供了声明和访问模块、应用程序和全局范围环境条目的方法,但这些需要特定的环境条目前缀。请参阅 Java EE 6 规范 了解更多信息。)运行时无法在 JNDI 中修改环境条目值。我建议在您的 EJB 上公开一个单独的方法来在本地获取和设置该值。
Environment entries are only visible in the application component's naming context (i.e.
java:comp/env
from theInitialContext
within the EJB or web module where it is declared). (Exception: Java EE 6 provides ways to declare and access module, application, and global-scoped environment entries, but those require specific environment entry prefixes. See EE.5.2.2 from the Java EE 6 specification for more information.)Environment entry values cannot be modified in JNDI at runtime. I'd suggest exposing a separate method on your EJB that gets and sets this value locally.