"javax.ejb.NoSuchEJBException:找不到有状态的bean:"

Aga*_*ata 4 java jboss ejb java-ee ejb-3.0

我在与Jboss和EJB 3.0的冒险中进一步努力.我使用EJB加入了Spring 3.0.我有3个模块 - 带有Spring控制器的web模块,带有我的EJB bean的ejb模块和带有dao或其他帮助器的其他类的spring mogule.一切都在耳边.

所以,在我的Spring Controller中,我有以下代码:

@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;
}
Run Code Online (Sandbox Code Playgroud)

在我的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!");

    }
}
Run Code Online (Sandbox Code Playgroud)

每个依赖项都被正确注入.当我使用无状态bean测试此代码时,它可以正常工作.当谈到有状态bean时,我调用我的方法sayGoodbye()我不能再调用这个bean.我得到了例外:

javax.ejb.NoSuchEJBException: Could not find stateful bean: a74a2l-n1u5tx-gcwd0e6a-1-gcwd18fo-9h
Run Code Online (Sandbox Code Playgroud)

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

Pas*_*ent 5

您不能将有状态会话Bean(SFSB)注入到多线程组件中,这些组件可能由多个并发客户端(如Servlet或Controller)共享.改为执行JNDI查找并将bean放入HttpSession.

也可以看看