-
Dec 8th, 2009, 11:18 AM
#1
context initialization in multi module project
Hello.
What is correct way to initialize application context, if I have several utility libraries in lib/ folder, with their spring config xmls? Those libraries expose their services via service facade. Is it correct for facade to be Java singleton? And to initialize context in getInstance() method?
getInstance(){
//....
ctx = new ClassPathXmlApplicationContext("spring-services.xml", "spring- config.xml");
//....
}
I know, it works, but ...
Here is structure of my EAR archive...
myApp.ear
|
|---lib/
| |--mySpringLib1.jar
| |--mySpringLib2.jar
| |-- ...
|
|--- ejb.jar
|---web.war
Thank you,
Miroslav
-
Dec 9th, 2009, 03:11 AM
#2
Hi,
There is another way to intialise the configuration files without using a singleton class.
Its in web.xml,you have to add ana entry for both contextConfigLocation and a listener for the same.
The <context-param>:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
The <listener>:
<listener>
<listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
</listener>
You can have multiple config files in the param-value tag by using comma seperated values.
Spring will read all those config files and will create an instance of the all the bean declared in the xml files.
By putting the above configuration,you dont need to initialise the XML Factory.
Hope it helps
Tags for this Thread
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