Announcement Announcement Module
Collapse
No announcement yet.
Newbie - moving from EJB to Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie - moving from EJB to Spring

    Hi,

    I'm an EJB programmer, and I'm starting to look at Spring for the first time, I have a copy of Spring in Action, but ... I'm getting stuck on something simple. Can anyone help me?

    I have a J2SE programme, a couple of beans, it loads Spring and the XML file does the injection of dependency. All fine as far as it goes.

    But when it comes to J2EE, I'm a bit lost.

    In a normal EJB application, you have an interface, implemented as a stateless session bean, which acts as the "entry point" to the middle tier. You might stick @WebService on this session bean, to make it a webservice; or you might call it using the remote interface from some J2SE or Struts client (presuming you don't have your presentation layer in the same EAR as the middle tier).

    But in Spring ... what do you do? How does your client (not in the same WAR) call the middle tier? What is the normal way to provide an interface to the middle tier in Spring? (I may be confusing myself here, so bear with me!)

    Developing this a little further; the reason you have EJBs in a J2EE application is that the EJB takes a little while to start up. So rather than make the client wait while you do this, you get the EJB container to start up a pool of these things offline, and you just grab a handle to an existing bean when your client request comes in.

    What is the equivalent in Spring? Do you really start a new Spring IoC container every time an HTTP request comes in?

    Thanks!

    Roger

  • #2
    I suggest reading the book further before asking the questions, the book also answers them, as well as the spring reference guide.

    You let the ContextLoaderListener load the applicationcontext (once!) and refer from your controller/actions to the beans loaded by that context. So NO you don't (re)load the application, unless you want to run out of resources.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      I suggest reading the book further before asking the questions...
      Ouch.

      You let the ContextLoaderListener load the applicationcontext (once!) and refer from your controller/actions to the beans loaded by that context. So NO you don't (re)load the application, unless you want to run out of resources.
      Thank you -- this gives me something to work with.

      All the best,

      Roger Pearse

      Comment


      • #4
        Sorry, didn't want to offend anyone. So my apologies for that.

        The web chapter is probably worth reading as that covers enterprise application, another read would be the EJB chapter in the reference guide (how to integrate spring into a EJB container).

        BUt in general you bootstrap your container once and dependency inject the dependencies for your application. For a web app that is the ContextLoaderListener and/or the DispatcherServlet.

        Comment


        • #5
          I was pretty sure that you'd want to load the container only once, lightweight or not, so thank you! I will look at those chapters. I did look at the using EJB's with Spring -- either Spring calling the EJB, or vice versa -- but clearly I need to look more. I appreciate the tip on how it's done -- I can now look those classes up and see what they do!

          Cheers,

          Roger

          Comment


          • #6
            There is a spring based Petclinic (and some more samples) I suggest taking a look at that. It gives you a working sample.

            Comment


            • #7
              Petclinic is the one, is it? Thanks -- will take a look.

              The problem I found is that most of the stuff I read seemed to presume you were using Spring MVC, which we weren't. There's some existing rich client that has to connect to the Spring middle tier. I did see an interesting example in "Spring Recipes" ch. 11, tho, which did not presume this, and was very good on getting a servlet to call Spring. However it didn't answer my question about starting containers and EJB-like behaviour.

              Comment

              Working...
              X