Results 1 to 4 of 4

Thread: Design/Architec Question about replacing EJB with SPRING

  1. #1
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    54

    Default 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. #2
    Join Date
    Sep 2004
    Location
    Texas
    Posts
    155

    Default

    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 );
       }
    }
    Corby

  3. #3
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    54

    Default

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

  4. #4
    Join Date
    Sep 2004
    Location
    Texas
    Posts
    155

    Default

    Quote 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.

    Quote 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.
    Corby

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 1
    Last Post: Sep 29th, 2005, 10:33 AM
  3. Newbie Question - The Ideal Spring Solution
    By conorp in forum Architecture
    Replies: 3
    Last Post: Aug 23rd, 2005, 03:22 AM
  4. Spring debugging question : IoC
    By etienno in forum Architecture
    Replies: 7
    Last Post: Apr 13th, 2005, 08:26 AM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •