获取并设置;来自远程客户端

发布于 2025-01-01 16:39:26 字数 1414 浏览 2 评论 0原文

我有带有远程接口 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾冷 2025-01-08 16:39:26

有什么想法,如何获取这个变量吗?

环境条目仅在应用程序组件的命名上下文中可见(即声明它的 EJB 或 Web 模块内的 InitialContext 中的 java:comp/env)。 (例外:Java EE 6 提供了声明和访问模块、应用程序和全局范围环境条目的方法,但这些需要特定的环境条目前缀。请参阅 Java EE 6 规范 了解更多信息。)

第二个问题是:我可以编辑它的值吗?

运行时无法在 JNDI 中修改环境条目值。我建议在您的 EJB 上公开一个单独的方法来在本地获取和设置该值。

Is there any ideas, how to get this variable?

Environment entries are only visible in the application component's naming context (i.e. java:comp/env from the InitialContext 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.)

And the second question is: can i edit its value?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文