如题,我的开发环境是windows的一个web应用,但是是在一个main方法中直接加载配置文件
具体代码片段:
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:study/event/applicationContext-event.xml");
spring怎么知道classpath是哪个路径?
看了下ClassPathResource的源代码,在它的方法:
public InputStream getInputStream() throws IOException {
InputStream is = null;
if (this.clazz != null) {
is = this.clazz.getResourceAsStream(this.path);
}
else {
is = this.classLoader.getResourceAsStream(this.path);
}
if (is == null) {
throw new FileNotFoundException(
getDescription() + " cannot be opened because it does not exist");
}
return is;
}
里,程序运行到这里的时候this.path显示的是:study/event/applicationContext-event.xml,所以不知道spring是怎么知道去正确的路径查找资源(study/event/applicationContext-event.xml)的
[b]问题补充:[/b]
我很想知道spring是怎么知道classpath是哪个的?也就是说它是在什么地方确定了classpath目录的路径的?
[b]问题补充:[/b]
但是我系统都没有定义那个classpath。
[b]问题补充:[/b]
java.class.path这个系统属性是什么时候定义的呢?因为我自己是没定义的,所以我认为是不是:
1 如果是在IDE里面跑java程序,那么又IDE定义这个变量
2 如果是在服务器里面运行java程序,那么由服务器定义
是这样的吗?