ApplicationContext ac = new Classpathxmlapplicationcontext ("Applicationcontext.xml");
DataSource ds = (DataSource) Ac.getbean ("DS");
System.out.println (DS);
The parameters in the Classpathxmlapplicationcontext silently go to the classpath path to find. You can add Classpath:applicationContext.xml.
If more than one XML file can be a new string array
ApplicationContext ac = new Classpathxmlapplicationcontext (new string[]{"Applicationcontext.xml", " Applicationcontext_dao.xml "});
If you use a file path, you can also
ApplicationContext ac = new Classpathxmlapplicationcontext ("file:f:\\lee\\workspace\\struts2\\oa\\src\\ Applicationcontext.xml ");
Note: If the absolute path is dead, file: is required.
Differences in the use of Classpathxmlapplicationcontext and Filesystemxmlapplicationcontext
If you use an absolute path in the Filesystemxmlapplicationcontext parameter, you can add a file prefix or no file prefix, which is one of the differences with Classpahtxmlapplicaitoncontext.
ApplicationContext ac = new Filesystemxmlapplicationcontext ("file:f:\\lee\\workspace\\struts2\\oa\\src\\ Applicationcontext.xml ");
ApplicationContext ac = new Filesystemxmlapplicationcontext ("f:\\lee\\workspace\\struts2\\oa\\src\\ Applicationcontext.xml ");
The second one is also possible.
If you're looking for a class path, you have to add classpath.
ApplicationContext ac = new Filesystemxmlapplicationcontext ("Classpath:applicationContext.xml");
If the path is not absolute and classpath is not specified, it is found by default in the path of the project
ApplicationContext ac = new Filesystemxmlapplicationcontext ("Src/applicationcontext.xml");
ApplicationContext ac = new Filesystemxmlapplicationcontext ("Webcontent/applicationcontext.xml");
And the path is case insensitive
Summary: Classpathxmlapplicationcontext default is to load the classpath path under the configuration file, and Filesystemxmlapplicationcontext default is to load the file system configuration file
Classpathxmlapplication and Filesystemxmlapplicationcontext use differences in spring