caused By:java.io.FileNotFoundException:applicationContext.xml (the system cannot find the file specified)
Method One:
ApplicationContext context = new Classpathxmlapplicationcontext ("Applicationcontext.xml");
Applicationcontext.xml in src directory
Method Two:
ApplicationContext context = new Filesystemxmlapplicationcontext ("Src/applicationcontext.xml");
Applicationcontext.xml in src directory
And then Drivecar dc= (Drivecar) Ctx.getbean ("Drivecar"), you can use the ...
Note that the above two types of loading are paths.
Then convert them to beanfactory. The bean that needs to be used is obtained using Getbean (""), which can be either by ID or name.
There are two other ways to load:
Method Three: Classpathresource resource = new classpathresource ("Applicationcontext.xml");
Beanfactory factory = New xmlbeanfactory (Resource);
Method Four:
Resource Resource = new filesystemresource ("Src/applicationcontext.xml");
Beanfactory factory = New xmlbeanfactory (Resource); The
also needs to be aware of the different paths above. In fact classpath the corresponding path is the SRC directory, and filesystem is relative to the project directory. So their path is different, load it carefully, otherwise it will be reported java.io.FileNotFoundException (the system can not find the specified file) of the exception.