Reputation: 21
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 POJO rather than manual JNDI look up in to POJO through spring(using @Resource
and SpringBeanAutowiringInterceptor
)?.
Is there any way to do that?
Upvotes: 2
Views: 2857
Reputation: 403481
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.
Upvotes: 1
Reputation: 570345
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.
Upvotes: 2