Spring的配置和实例化

来源:互联网 发布:程序员android工作总结 编辑:程序博客网 时间:2024/05/22 06:11

1.引入jar包  Spring.jar 和  commons-logging.jar  //这样就可以进行基本的实例化

2.如果使用了切面编程还需要Jar包

aspectjweaver.jar 和 aspectjrt.jar 和 cglib-nodep-2.1_3.jar

3.如果使用了JSR-250中的注解 则还需要如下包

common-annotations.jar

实例化Spring容器的两种方法:

1.在类路径中寻找配置文件

 ApplicationContext ac = new ClassPathXmlApplicationContext("Bean.xml"); //参数可是String或者String[]

2.在文件系统中寻找配置文件

ApplicationContext ac  = new FileSystemXmlApplicationContext("Bean.xml"); 

此方法不适合用,不同的使用地点的文件系统路径是不同的,所以不提倡用