我在与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 …Run Code Online (Sandbox Code Playgroud)