关于Spring中ApplicationContext的说明
来源:互联网 发布:淘宝不是卖家怎么贷款 编辑:程序博客网 时间:2024/04/28 05:25
关于Spring中ApplicationContext的说明
一、简单的用ApplicationContext做测试的话,获得Spring中定义的Bean实例(对象).可以用:
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");RegisterDAO registerDAO = (RegisterDAO)ac.getBean("RegisterDAO");
如果是两个以上:
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","dao.xml"});
或者用通配符:
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/*.xml");
二、ClassPathXmlApplicationContext[只能读放在web-info/classes目录下的配置文件]和FileSystemXmlApplicationContext的区别
classpath:前缀是不需要的,默认就是指项目的classpath路径下面;
如果要使用绝对路径,需要加上file:前缀表示这是绝对路径;
对于FileSystemXmlApplicationContext:
默认表示的是两种:
1.没有盘符的是项目工作路径,即项目的根目录;
2.有盘符表示的是文件绝对路径.
如果要使用classpath路径,需要前缀classpath:
public class HelloClient {protected static final Log log = LogFactory.getLog(HelloClient.class);public static void main(String[] args) {Resource resource = new ClassPathResource("appcontext.xml"); BeanFactory factory = new XmlBeanFactory(resource);// 用classpath路径ApplicationContext factory = new ClassPathXmlApplicationContext("classpath:appcontext.xml");ApplicationContext factory = new ClassPathXmlApplicationContext("appcontext.xml");// ClassPathXmlApplicationContext使用了file前缀是可以使用绝对路径的ApplicationContext factory = new ClassPathXmlApplicationContext("file:F:/workspace/example/src/appcontext.xml");// 用文件系统的路径,默认指项目的根路径ApplicationContext factory = new FileSystemXmlApplicationContext("src/appcontext.xml");ApplicationContext factory = new FileSystemXmlApplicationContext("webRoot/WEB-INF/appcontext.xml");// 使用了classpath:前缀,这样,FileSystemXmlApplicationContext也能够读取classpath下的相对路径ApplicationContext factory = new FileSystemXmlApplicationContext("classpath:appcontext.xml");ApplicationContext factory = new FileSystemXmlApplicationContext("file:F:/workspace/example/src/appcontext.xml");// 不加file前缀ApplicationContext factory = new FileSystemXmlApplicationContext("F:/workspace/example/src/appcontext.xml");IHelloWorld hw = (IHelloWorld)factory.getBean("helloworldbean");log.info(hw.getContent("luoshifei"));}}
0 0
- 关于Spring中ApplicationContext的说明
- 关于Spring中ApplicationContext的说明
- 关于Spring中ApplicationContext的说明
- Spring中ApplicationContext的说明
- 关于Spring框架中applicationContext的问题
- Spring的applicationContext配置文件中<bean>标签的属性说明
- Spring中关于applicationContext.xml文件的配置实例
- 关于JavaWeb应用中获取Spring的ApplicationContext
- Spring的applicationContext.xml的bean 说明
- Spring中ApplicationContext的使用说明
- spring配置文件applicationContext说明
- 关于Spring中applicationContext.xml路径问题
- 关于spring的配置文件applicationcontext.xml
- Spring+Hibernate:在applicationContext.xml中配置C3P0参数说明
- spring+hibernate:在applicationCOntext.XML中配置C3P0参数说明
- spring+hibernate:在applicationCOntext.XML中配置C3P0参数说明
- Spring:关于ApplicationContext
- spring applicationContext.xml 文件头的配置说明
- How to uninstall Python 2.7 (installed by yourself) on a Mac OS
- 高仿QQ6.0侧滑菜单之滑动优化(二)
- 浙江绿盟科技笔试题
- 安装grafana-zabbix插件
- 哈希表算法
- 关于Spring中ApplicationContext的说明
- 默认开机启动GPRS功能
- Redis的安装和部署(Linux)
- 关于umask及相关权限知识的整理
- ViewController详解
- Action层, Service层 和 Dao层的功能区分
- 配置rsync服务端和客户端并同步
- js生成guid方法
- Android 开发的一些坑