1
package com;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringExam {
public static void main(String[] args) {
ApplicationContext applicationContext=
new ClassPathXmlApplicationContext ("com/applicationContext.xml");
String path = SpringExam.class.getCanonicalName();
System.out.println(path);
}
}
配置文件路径带包名,这个是相对于编译后的 classpath
第二种方式用filesystem...
public static void main(String[] args) {
ApplicationContext applicationContext=
// new ClassPathXmlApplicationContext ("com/applicationContext.xml");
new FileSystemXmlApplicationContext ("src/com/applicationContext.xml");
String path = SpringExam.class.getCanonicalName();
System.out.println(path);
}
这个路径要加上src,也不知道为啥
第三个方式
new FileSystemXmlApplicationContext ("file:D:\\workspace\\j2ee\\springdemo\\src\\com\\applicationContext.xml");
第四个方式
new FileSystemXmlApplicationContext ("D:\\workspace\\j2ee\\springdemo\\src\\com\\applicationContext.xml");
2
property文件要在src根目录下才行
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/xxx
username=xxx
password=xxx