"1" Construction works from scratch
The simplest: Http://www.cnblogs.com/alipayhutu
where d) in exchange for:
ApplicationContext context = new Classpathxmlapplicationcontext ("config +");
Main main = (main) Context.getbean ("main");
For more information, refer to: http://hi.baidu.com/shutaodream/blog/item/a51b9f1bf1da00b94aedbcd0.html
"2" Eclipse, Project/file directory
1. Get the system root directory
- System.getproperty ("User.home");
- such as output, C:\Users\hutu
2. Get the Project Catalog
- System.getproperty ("User.dir");
- such as output, D:\workspaces\workspace1\myProject
3. New file, default in project directory
- New File ("Xxx.txt"). GetAbsolutePath ();
- such as output, D:\workspaces\workspace1\myProject
4. Configuration file path
- ApplicationContext context = new Classpathxmlapplicationcontext ("config +");
- . XML,. Properties, etc., by default or from the "Engineering catalog" to find
1). can also use absolute path, really not recommended Ah, too not elegant;
2). Alternatively, place the log4j file in the bin/directory:
a). In the Code, Propertyconfigurator.configure ("bin/log4j.properties");
b). In the Code, propertyconfigurator.configure (classloader.getsystemresource("log4j.properties"));
c). Note that it must be located in the bin Direct directory and not in the deeper directory of the bin. But is this a god-horse pinch?
5. Query the directory where the. class files for a class
- Main.class.getResource ("");
- For example output, D:\workspaces\workspace1\myProject\bin\com\hutu\log4j\
- Note that querying the package ancestor path simply changes the parameter to "/"
6. Query the directory where the thread context resides
- Thread.CurrentThread (). Getcontextclassloader (). GetResource ("");
- such as output, D:\workspaces\workspace1\myProject\bin\
7. Query the directory where the ClassLoader of a class
- Main.class.getClassLoader (). GetResource ("");
- such as output, D:\workspaces\workspace1\myProject\bin\
8. Query the directory where ClassLoader is located
- Classloader.getsystemresource ("");
- such as output, D:\workspaces\workspace1\myProject\bin\
Interpreting Java Resource files