Announcement Announcement Module
No announcement yet.
Bootstrap Spring in a J2ee Application. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bootstrap Spring in a J2ee Application.

    I have seen documented a nice declarative approach to bootstap Spring (load the application context xml) in a web-app through the web.xml like so:

    <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>

    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>

    I have a enterprise app deployed as an ear file but with no web-app element. Is there any declarative way to bootstap Spring in such an application? Can anyone suggest a nice clean way to bootstrap Spring in an enterprise app.

    Any suggestions are most welcome.

  • #2
    Is the question then how to integrate Spring with EJBs? In that case see here.

    If I missed the point, please post some more details about your requirements.



    • #3
      Sorry, I'm finding it quite difficult to express my problem.

      We have a thin layer of EJB SLSB. Behind these we want to use Spring DAO and Hibernate. I have configured everything nicely in my applicationContext.xml but wan to have the bean factory initialised when my ear file is deployed or on server startup. I wanted advise on the best way to do this in a j2ee app that has no web-app (war).

      Because i am new to spring it is difficult for me to express the problem i am having.

      I know i need to run some code like so:

      ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
      new String[] {"applicationContext.xml", "applicationContext-part2.xml"});
      // of course, an ApplicationContext is just a BeanFactory
      BeanFactory factory = (BeanFactory) appContext;

      But where should i put this code to ensure once the ear is deployed everything is initialised at startup???


      • #4
        Ok, I see. The problem is, that in the JEE context only the Servlet spec specifies such initialization hooks.

        Anyway, there is nothing wrong in providing a WAR file with web.xml specifying a ContextLoaderListener. From that you can specify an application context which contains your initialization beans.
        Even though you have no web application, that approach is perfectly fine and portable as well. I have done this before and know of others which did so as well.



        • #5
          Ok, then that is what I shall do.

          Thank you for the help.