I know that:
ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
loads context definition from an XML file located in the classpath, treating context definitions as classpath resources.
ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml");
loads context definition from an XML file in the filesystem.
XmlWebApplicationContext
loads context definition from an XML file contained within a web application.
But, what does it exactly mean??
Thanks :)
I think above opinion may have something wrong,
FileSystemXmlApplicationContext
can not access your whole file system, what it can only scan is your whole project folder.In order to prove my conclusion i make a example, first usingClasspathXmlApplicationContext
and everything is normal, the second time i move beans.xml file to my desktop folder, so there is no beans.xml file in the project hirachy, and change ClassPathXmlApplicationContext toFileSytemXmlApplicationContext
and something goes wrong, error trace below:So FileSystemXmlApplicationContext can only detect the current project all folder. For example you make a directory which named
config
under the project root directory, and you can change your Main Class code like below:And everything will ok again. So if all like sinuhepop said i think there should something need to be changed.
FileSystemXmlApplicationContext- You need to provide complete full path of xml bean ClassPathXmlApplicationContext - In this case you DONOT need to set full path, as long as classpath is set
ClassPathXmlApplicationContext
will read files from your classpath. They must be inclasses
folder of your web application or in ajar
in yourlib
folder.FileSystemXmlApplicationContext
can access all your file system, for examplec:/config/applicationContext.xml
.XmlWebApplicationContext
certainly can access to files contained in your web application, but this is not the most important thing. It implements WebApplicationContext and this means that it will detect ServletContextAware beans, register custom scopes (request, session, ...) among other things.