Spring如何获得容器对象
2015-11-10 12:50
471 查看
1.在classpath路径下寻找
2.
配置文件和Main这个类在同一个包中
3.有多个配置文件的情况
我们知道service会依赖dao,那么是不是意味着与配置文件读取的顺序有关呢?
这样也是可以的,它会自己处理依赖关系。它会自动初始化那些被依赖的对象。
4.
ApplicationContext ac = new ClassPathXmlApplicationContext("cn/itcast/spring/d_applicationContext/applicationContext_dao.xml");
2.
配置文件和Main这个类在同一个包中
ApplicationContext ac2 = new ClassPathXmlApplicationContext("applicationContext_dao.xml", Main.class);
3.有多个配置文件的情况
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[] {// "cn/itcast/spring/d_applicationContext/applicationContext_service.xml",// "cn/itcast/spring/d_applicationContext/applicationContext_dao.xml" });
我们知道service会依赖dao,那么是不是意味着与配置文件读取的顺序有关呢?
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[] {// "cn/itcast/spring/d_applicationContext/applicationContext_dao.xml",// "cn/itcast/spring/d_applicationContext/applicationContext_service.xml" });
这样也是可以的,它会自己处理依赖关系。它会自动初始化那些被依赖的对象。
4.
ApplicationContext ac2 = new ClassPathXmlApplicationContext(new String[] {// "applicationContext_dao.xml", "applicationContext_service.xml" },Main.class);
相关文章推荐
- java web 处理xml的方法
- jdk6版本下载地址
- MyEclipse中更改SVN密码
- No Hibernate Session bound to thread, and configuration does not allow creation
- mysql/Java服务端对emoji的支持
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- 第4条:通过私有构造器强化不可实例化的能力
- java截图工具的实现
- 【Spring】spring的自动装配(default-autowire="byName")
- Java enum的用法详解
- javax.el.PropertyNotFoundException: Property 'eyeSuggest' not readable on type org.smt.entity.Health
- JavaWeb学习篇——使用过滤器及装饰器设计模式解决全站乱码问题
- JSON对象 和 java对象互相转换
- java 实现WebService 以及不同的调用方式
- Java层与Jni层的数组传递
- Java6 WebService 使用集合
- eclipse配合Android Studio部署Android NDK开发环境
- eclipse export runnable jar- launch configuration 是空的|没有自己的main类
- Java6 WebService 使用复杂对象
- Java6 WebService客户端封装