יום שישי, 7 ביוני 2013

ApplicationContext loading

There is two ways to load application context xml file  in spring: classpathxmlapplicationcontext or filesystemxmlapplicationcontext.

FileSystemXmlApplicationContext:
Loads the application context acoording to a full path for an example 

  1: ApplicationContext context = new FileSystemXmlApplicationContext(
  2:    "I:\\Learn\\java\\maven\\executableJar\\mavenToExeJar\\SpringXMLConfig.xml");

The current path can be obtained by :


  1:   final String dir = System.getProperty("user.dir");
  2:         System.out.println("current dir = " + dir);

classpathxmlapplicationcontext
The spring application context should be in the CLASSPATH
Getting the current class path can be done  by:


  1: String theClassPath = System.getProperty("java.class.path");
  2: System.out.println("theClassPath dir = " + theClassPath);
  3: 

An example for using classpathxmlapplicationcontext :


  1: ApplicationContext context = new ClassPathXmlApplicationContext (
  2:         "SpringXMLConfig.xml");

Resources
http://en.wikipedia.org/wiki/Classpath_(Java)
http://codeissue.com/issues/i84e1f376448bef/classpathxmlapplicationcontext-vs-filesystemxmlapplicationcontext

אין תגובות:

הוסף רשומת תגובה