The difference between Classpathxmlapplicationcontext and Filesystemxmlapplicationcontext

Source: Internet
Author: User
Tags log log
For Classpathxmlapplicationcontext (), classpath: prefix is not required, default refers to the project classpath path below;
If you want to use an absolute path, you need to add a file: prefix to indicate that this is an absolute path;
For Filesystemxmlapplicationcontext (), the default representation is two types:
1, no drive letter is the project work path, that is, the root directory of the project;
2, a drive letter represents the absolute path of the file.

If you want to use the classpath path, prefix classpath is required:

public class Helloclient {protected static final log log = Logfactory.getlog (Helloclient.class);

       public static void Main (string[] args) {//Resource Resource = new Classpathresource ("Appcontext.xml");

Beanfactory factory = new Xmlbeanfactory (Resource);

With Classpath path can also//ApplicationContext factory=new classpathxmlapplicationcontext ("Classpath:appcontext.xml");

       ApplicationContext factory=new classpathxmlapplicationcontext ("Appcontext.xml"); ApplicationContext factory=new classpathxmlapplicationcontext ("File:g:/1java Utility Project resource/2SPRING/1 proficient in spring full jar code/

Workspace/workspace/example6/src/appcontext.xml ");     

Using the file system path//ApplicationContext factory=new filesystemxmlapplicationcontext ("Src/appcontext.xml"); Use the classpath: prefix as a flag, so that Filesystemxmlapplicationcontext can also read the relative path under classpath//ApplicationContext Factory

     =new filesystemxmlapplicationcontext ("Classpath:appcontext.xml"); ApplicationContext FactoRy=new filesystemxmlapplicationcontext ("File:g:/1java Utility Project resource/2SPRING/1 proficient in spring full jar code/workspace/workspace/

        Example6/src/appcontext.xml "); ApplicationContext factory=new filesystemxmlapplicationcontext ("G:/1java Utility Project resource/2SPRING/1 proficient in spring full jar code/workspace

/workspace/example6/src/appcontext.xml ");

        Ihelloworld HW = (ihelloworld) factory.getbean ("Helloworldbean");

    Log.info (Hw.getcontent ("Luoshifei")); }

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.