Announcement Announcement Module
Collapse
No announcement yet.
Design/Architec Question about replacing EJB with SPRING Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Design/Architec Question about replacing EJB with SPRING

    Hi,

    I would like to know opinion of poeple that have done this work before. I need some design guide line before starting the job.

    I was given the opportunity to work on an Web Struts 1.0/EJB 1.0 application under Webphere 4.0.6. I have work for some months with Spring on previous project (JDBCTemplates, Hibernate, etc) and I think I might use Spring to help me making this application more testable, more deployable and better design.

    The pattern currently use in this web site is this:

    A Struts Action
    call an EJB "Delegate"
    call an EJB Manager Bean (doing the job)
    call some Entity Beans

    EJB is overkill for this kind of application.

    So first I decide to get ride of all EJB. I will try to use Hibernate instead of Entity Beans (at last resort Spring JDBCTemplate).

    I would like to replace Delegates and Manager Beans by Spring Pojo.

    I have a simple (Design) question : what is the best way to load the Spring beans inside the Struts Action? Is there a simple pattern to load the Spring context once and then use the Factory to load all Beans? I dont want to write a "SpringContextFactory" that would be a singleton to load the beans afterwhile. There is probably something already existing in Spring?

    Thanks

    Etienne.

  • #2
    You can make your StrutsActions extend org.springframework.web.struts.ActionSupport for easy access to the WebApplicationContext.

    You can use the following base class if you are comfortable autowiring your Struts actions.

    Code:
    public abstract class AutowireAction extends ActionSupport
    {
       protected void onInit()
       {
          XmlWebApplicationContext applicationContext = (XmlWebApplicationContext) getWebApplicationContext();
          applicationContext.getBeanFactory().autowireBeanProperties( this, AUTOWIRE_BY_NAME, false );
       }
    }

    Comment


    • #3
      This is exactly was I was searching for!

      Is there any drawback to this solution? Like initialising too much beans?

      If I understood you correctly, it will auto-wire all bean set on the same type using the public setter of the bean?

      Thanks.

      Etienne.


      Small correction:

      Code:
      public class StrutsActionSupport extends ActionSupport {
      
      	   protected void onInit()
      	   {
      		  XmlWebApplicationContext applicationContext = (XmlWebApplicationContext) getWebApplicationContext();
      		  applicationContext.getBeanFactory().autowireBeanProperties( this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false );
      	   }
      	}

      Comment


      • #4
        Originally posted by etienno
        Is there any drawback to this solution? Like initialising too much beans?
        As long as you are comfortable with autowiring semantics, there are no drawbacks. Struts only creates one instance of each action, so you will only incur the autowiring overhead once.

        Originally posted by etienno
        If I understood you correctly, it will auto-wire all bean set on the same type using the public setter of the bean?
        It will autowire all beans set with matching names. If you want to match beans set on the same type, change AUTOWIRE_BY_NAME to AUTOWIRE_BY_TYPE.

        Comment

        Working...
        X