Results 1 to 2 of 2

Thread: Echo framework and Spring

  1. #1
    Join Date
    Aug 2004
    Posts
    1

    Default Echo framework and Spring

    Does anyone have any tips or suggestions on how to integrate the Echo framework for the web tier with a spring app?

  2. #2
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    Preliminary note: I've never worked with Echo, just had a look at its tutorials and javadocs.

    As far as I see, each Echo application has to derive from the EchoServer servlet, which in turn has to provide a new subclass of EchoInstance on each newInstance() callback. I'll also assume that a Spring root application context is loaded in the web application, via Spring's ContextLoaderListener in web.xml.

    Code:
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    As EchoServer derives from HttpServlet, you have access to the ServletContext via getServletContext(). This means that you can fetch a reference to the Spring root application context via the usual WebApplicationContextUtils.getWebApplicationContex t(servletContext) method, getting access to any beans there.

    You could either pass the WebApplicationContext reference itself to each new EchoInstance, or specific beans that you have fetched from the ServletContext. As an EchoInstance seems to be a pretty coarse-grained object, very central to an Echo application, it's probably preferable to pass the WebApplicationContext reference itself in.

    Code:
    public class NumberGuessServlet extends EchoServer &#123;
    
      public EchoInstance newInstance&#40;&#41; &#123;
        WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext&#40;getServletContext&#40;&#41;&#41;;
        return new NumberGuess&#40;wac&#41;;
        // or new NumberGuess&#40;myBeanFromWac, myOtherBeanFromWac&#41;;
      &#125;
    &#125;
    Alternatively, you could define the EchoInstance itself as a Spring prototype bean, probably in a separate XML file joined into your Spring root context. This would allow you to declaratively wire it with middle tier beans, using all of Spring's bean setup power. You would then simply call getBean on the Spring context to get the EchoInstance:

    Code:
    <beans>
      
      <bean id="numberGuess" class="numberguess.NumberGuess">
        <property name="myProperty">...</property>
      </bean>
    
    </beans>
    Code:
    public class NumberGuessServlet extends EchoServer &#123;
    
      public EchoInstance newInstance&#40;&#41; &#123;
        WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext&#40;getServletContext&#40;&#41;&#41;;
        return &#40;NumberGuess&#41; wac.getBean&#40;"numberGuess", NumberGuess.class&#41;;
      &#125;
    &#125;
    So in total, integration between an Echo web tier and a Spring middle tier should be straightforward, with a variety of options.

    Juergen

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: 5
    Last Post: Aug 9th, 2008, 05:30 AM
  3. Spring code remarks
    By Alarmnummer in forum Architecture
    Replies: 18
    Last Post: Apr 7th, 2005, 07:17 AM
  4. 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
  •