开发者

Adding a dependency to an EJB

开发者 https://www.devze.com 2023-04-03 11:44 出处:网络
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 wiremyDependency without having to use \'new\'.

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 My开发者_开发知识库OtherBean myOtherBean;


    private MyDependency myDependency;
    ...

}


This is well described in the Spring documentation:

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(...);
    }
    ...
}

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

0

精彩评论

暂无评论...
验证码 换一张
取 消