“javax.ejb.NoSuchEJBException:找不到有状态 bean:”

发布于 2024-09-14 14:36:40 字数 1377 浏览 2 评论 0原文

我在 Jboss 和 EJB 3.0 的冒险中继续挣扎。 我通过 EJB 加入了 Spring 3.0。我有 3 个模块 - 带有 Spring 控制器的 Web 模块、带有 EJB beans 的 ejb 模块以及带有其他类(如 dao 或一些助手)的 spring 模块。尽在耳中。

因此,在我的 Spring 控制器中,我有以下代码:

@Controller
public class IndexController {

    @EJB
    PaymentRemote paymentRemote;

    @RequestMapping(value = "/index")
    public ModelAndView index() throws Exception {
        ModelAndView mav = new ModelAndView("index/index");     

        paymentRemote.savePayment(123, "bla222");
        paymentRemote.sayGoodbye();
           return mav;
}

在我的 EJB 模块中,我有以下有状态 bean:

@Stateful
@Interceptors( SpringBeanAutowiringInterceptor.class)
public class PaymentRemoteImpl implements PaymentRemote{

    @Autowired
    ExampleService exampleService;

    public void savePayment(long payment, String name) throws Exception {
        exampleService.savePayment(123, "kk");

    }

    @Remove
    public void sayGoodbye() {
        System.out.println("I want to finish my task here!");

    }
}

每个依赖项都被正确注入。当我使用无状态 bean 测试此代码时,它工作得很好。当谈到有状态 bean 时,当我调用方法 sayGoodbye() 时,我无法再次调用该 bean。我得到了例外:

javax.ejb.NoSuchEJBException: Could not find stateful bean: a74a2l-n1u5tx-gcwd0e6a-1-gcwd18fo-9h

我不明白这种情况:/我要求容器删除该 bean,但后来我想再次使用它,但它想再次为我找到相同的 bean。我认为虽然我要求删除它,但它会根据我的要求再次创建。 有人可以帮我解决我的问题吗?我被困住了。

I'm struggling futher in my adventure with Jboss and EJB 3.0.
I joined Spring 3.0 with EJB. I have 3 modules - web module with Spring controllers, ejb module with my EJB beans and spring mogule with other classes like dao or some helpers. All in the ear.

So, in my Spring Controller I have the following code:

@Controller
public class IndexController {

    @EJB
    PaymentRemote paymentRemote;

    @RequestMapping(value = "/index")
    public ModelAndView index() throws Exception {
        ModelAndView mav = new ModelAndView("index/index");     

        paymentRemote.savePayment(123, "bla222");
        paymentRemote.sayGoodbye();
           return mav;
}

In my EJB module I have the following stateful bean:

@Stateful
@Interceptors( SpringBeanAutowiringInterceptor.class)
public class PaymentRemoteImpl implements PaymentRemote{

    @Autowired
    ExampleService exampleService;

    public void savePayment(long payment, String name) throws Exception {
        exampleService.savePayment(123, "kk");

    }

    @Remove
    public void sayGoodbye() {
        System.out.println("I want to finish my task here!");

    }
}

Every dependency is injected properly. When I test this code with stateless beans it works just fine. When it comes to stateful beans when I call my method sayGoodbye() I can't call again this bean. I get the exception:

javax.ejb.NoSuchEJBException: Could not find stateful bean: a74a2l-n1u5tx-gcwd0e6a-1-gcwd18fo-9h

I don't understand this situation :/ I asked the container to remove the bean but later on I would like to use it again but it wants to find me again the same bean. I thought that although I asked to remove it it will create on my request again.
Could anyone kindly help me with my problem? I'm stucked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

落墨 2024-09-21 14:36:40

您不能将有状态会话 Bean (SFSB) 注入到可能由多个并发客户端(如 Servlet 或控制器)共享的多线程组件中。相反,执行 JNDI 查找并将 bean 放入 HttpSession 中。

另请参阅

You can't use injection of Stateful Session Beans (SFSB) into a multi-threaded component that may be shared by multiple concurrent clients like a Servlet or a Controller. Perform a JNDI lookup instead and put the bean into the HttpSession.

See also

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