-
Jun 13th, 2006, 10:57 AM
#1
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.
-
Jun 14th, 2006, 01:22 AM
#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.
Regards,
Andreas
-
Jun 14th, 2006, 04:28 AM
#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???
-
Jun 14th, 2006, 05:47 AM
#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.
Regards,
Andreas
-
Jun 14th, 2006, 05:50 AM
#5
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
-
Forum Rules