How to Use Spring from EJB3

Jan 9, 2009

This is a short instruction how to inject a spring-managed bean into EJB3 component


  1. Read SpringFratamework’s reference here:

  2. Place to ejb module’s classpath a file beanRefContext.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">
     <bean id="myBeanFactory" class="">
      <constructor-arg value="myApplicationContext.xml"/>
  3. Create application context file named myApplicationContext.xml and define you beans there. Place this file to the ejb module’s classpath.

  4. Annotate your Stateless Session Bean:

    public class MyFacadeBean implements MyFacade {
      private MySpringComponent component;
          public void foo() {
  5. Deploy and test Your application.

See Also

How To Export Spring Managed Bean To JNDI

Sometimes it is necessary to export a spring managed bean to JNDI context. Here I want to show how do it.

In spring, there is a bean that provides a similar functionality for exporting to MBean server: MBeanExporter. Unfortunately, there is no standard JNDI bean exporter implementation in Spring Framework (current version is 2.5.6) - (Why?). But it’s easy to write it yourself

Configuring WS-Security for Axis 1.4 client

I was looking how to enable WS-Security features in the Axis client to my web service application. I have tested it with Axis 1.4 client.

logo   Never miss a story, subscribe to our newsletter