Announcement Announcement Module
Collapse
No announcement yet.
context initialization in multi module project Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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

    Comment

    Working...
    X