gpt4 book ai didi

java - EJB 2.1 到 EJB 3.1 迁移 - 未找到名称的 session EJB

转载 作者:行者123 更新时间:2023-12-02 03:03:11 28 4
gpt4 key购买 nike

I am migrating Ejb 2.1 to Ejb 3.1. I changed Java Version from 1.6 to 1.8, and Ejb Version from 2.1 to 3.1. Once I made the changes, I am getting problems in the ibm-ejb-jar-bnd.xml and ibm-ejb-jar-ext.xml files.I am getting these messages:

1: Session EJB with name 'abcEJB' not found
2: Resource reference with name 'ResourceRef_xyz' not found for this EJB or interceptor

Am I missing anything?

enter image description here

<小时/>

enter image description here

最佳答案

几年前我已经从 EJB 2.1 迁移到 EJB 3.1,我记得遇到了与您相同的问题和错误。

虽然我不记得解决该问题的确切操作,也不记得我一路上遇到的其他问题,但我会告诉您我是如何解决所有问题的,包括这个问题。

注意:迁移并不是一件容易的事,但按照描述的后续步骤操作将为您节省以后的很多麻烦。

  1. 使用适当的注释来注释 session Bean 和接口(interface):就我而言,我有 EJB 2.1 bean 的远程接口(interface)。由于我的应用程序中不需要实际的远程接口(interface),因此我将它们切换为本地接口(interface)。
  2. 清空 ibm-ejb-jar-bnd.xml 和 ibm-ejb-jar-ext.xml enter image description here
  3. 将客户端更改为使用 DI、JNDI 名称进行查找。就我而言,我使用了 JNDI 查找。

现在代码应该如下所示:

session Bean接口(interface):

@Local
public interface MySessionInterface {
// TODO :: declare business methods
}

session bean 实现:

@stateless
public interface MySessionBeanImpl implements MySessionInterface {
// TODO :: implement business methods
}

使用 JNDI 查找 EJB 的服务定位器:

public class ServiceLocator {
public final <T> T getLocalSession(Class<T> _class) throws NamingException {
return (T) new InitialContext().lookup("ejblocal:" + _class.getName());
}
}

客户:

public class SessionClient {
public void performOperation() {
try {
MySessionInterface session = ServiceLocator.getLocalSession(MySessionInterface.class);
// TODO :: perform business logic here
} catch (NamingException e) {
// TODO :: handle exception
}
}
}

当然,服务定位器可以有以下改进,但为了简洁起见,我删除了它们:

  • 缓存结果,而不是每次都从 JNDI 中查找
  • 捕获已检查的异常 NamingException 并抛出您自己的运行时异常

希望您觉得它有用。

关于java - EJB 2.1 到 EJB 3.1 迁移 - 未找到名称的 session EJB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42167325/

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