Results 1 to 5 of 5

Thread: Bootstrap Spring in a J2ee Application.

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    16

    Default 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:

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

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

    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. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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.

    Regards,
    Andreas

  3. #3
    Join Date
    Jun 2006
    Posts
    16

    Default

    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. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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.

    Regards,
    Andreas

  5. #5
    Join Date
    Jun 2006
    Posts
    16

    Default

    Ok, then that is what I shall do.

    Thank you for the help.

Posting Permissions

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