gpt4 book ai didi

EJB 3.1 JSR 定义

转载 作者:行者123 更新时间:2023-12-04 19:09:40 28 4
gpt4 key购买 nike

在 EJB 3.1 JSR 中,它在第 16.3.4 节中声明

The container must ensure that the enterprise bean instances have only read access to their environment variables. The container must throw the javax.naming.OperationNotSupportedException from all the methods of the javax.naming.Context interface that modify the environment naming context and its subcontexts.

问题 1:根据 JSR,从无状态 bean 方法向 JNDI 添加/编辑对象(比如字符串“hello”)是不合法的?

所以如果这是真的,下面的代码应该会失败,但是当在我的 jboss 6 中测试它时,它工作得很好。

public void RebindVars() throws NamingException{
Context ctx = new InitialContext();
String testString = (String) ctx.lookup("java:comp/env/testString");
String newString = "helloRebindFromJndi"; //Assume that this is a valid call.
if (!testString.equals(newString)) {
ctx.rebind("java:comp/env/testString", newString);
}
}

问题 2:因为它在我的 jboss 中工作,是 jboss 的实现允许更多的需求还是我完全误解了 JSR?

我正在参加 EJB 认证,这就是我问这个问题的原因,所以无需评论我为什么要这样做 =)

最佳答案

我相信 EJB 规范所说的是真的。 ENC 是只读命名空间 - 在 JBoss AS 7.1.1 上尝试它应该会失败。

一些您可能感兴趣的进一步阅读:

关于EJB 3.1 JSR 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12818465/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com