开发者

How to inject session bean into a POJO using Spring

I am having a EJB 3.0 Session Bean which implements the Local interface, and I have a pure POJO also.

How can I inject a Session Bean into the P开发者_如何学编程OJO rather than manual JNDI look up in to POJO through spring(using @Resource and SpringBeanAutowiringInterceptor)?.

Is there any way to do that?


To inject an EJB3 into a POJO (which is possible since Spring 2.5), I think that you should use @EJB instead of @Resource. Quoting Spring EJB and JPA (read it all, it has many examples):

Don't forget to add:

<context:annotation-config/>

It allows various annotations to be detected in bean classes: Spring's @Required and @Autowired, as well as JSR 250's @PostConstruct, @PreDestroy and @Resource (if available), JAX-WS's @WebServiceRef (if available), EJB3's @EJB (if available), and JPA's @PersistenceContext and @PersistenceUnit (if available). Alternatively, you may choose to activate the individual BeanPostProcessors for those annotations.

Also have a look at Spring support for @EJB annotations: example? on the Spring forums.


One option is to use the poetically-named LocalStatelessSessionProxyFactoryBean, which creates a spring bean proxy pointing at the session EJB on JNDI. You can then wire this proxy into your POJO using the usual Spring wiring techniques. The proxy bean will implement the same local interface of your EJB.

See this section of the Spring manual for an example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜