向EJB添加依赖项 [英] Adding a dependency to an EJB

查看:79
本文介绍了向EJB添加依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向EJB添加依赖项。我该如何使用Spring?从属对象是常规服务对象。根据下面的代码,我想连接myDependency而不用使用 new。
EJB在Weblogic中运行。

I want to add a dependency to an EJB. How do I do this using Spring? The dependent object is a general service object. Based on code below I want to wire myDependency without having to use 'new'. The EJB runs in weblogic.

@Stateless(mappedName = "MyBean")
public class MyBean implements MyBeanRemote, MyBeanLocal {

    @EJB(name = "MyOtherBean")
    private MyOtherBean myOtherBean;


    private MyDependency myDependency;
    ...

}


推荐答案

春季文档

对于EJB 3会话Bean和消息驱动的Bean,Spring提供了一个
便捷的拦截器,该拦截器可解析EJB组件类:
org.springframework中Spring 2.5的@Autowired
批注。 ejb.interceptor.SpringBeanAutowiringInterceptor。
可以通过EJB组件类
中的@Interceptors批注或通过EJB部署描述符中的与拦截器绑定的XML元素
来应用此拦截器。

For EJB 3 Session Beans and Message-Driven Beans, Spring provides a convenient interceptor that resolves Spring 2.5's @Autowired annotation in the EJB component class: org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor. This interceptor can be applied through an @Interceptors annotation in the EJB component class, or through an interceptor-binding XML element in the EJB deployment descriptor.



@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class MyFacadeEJB implements MyFacadeLocal {

    // automatically injected with a matching Spring bean
    @Autowired
    private MyComponent myComp;

    // for business method, delegate to POJO service impl.
    public String myFacadeMethod(...) {
        return myComp.myMethod(...);
    }
    ...
}

无状态EJB和Spring但是,bean提供了几乎相同的可能性。将它们混合在一起似乎是不必要的复杂性。

Stateless EJBs and Spring beans, however, offer more or less the same possibilities. Mixing them together seems like unnecessary complexity.

这篇关于向EJB添加依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆