1.将xxx.properties文件转换成Properties对象,用到下面两个方法。
org.springframework.core.io.FileSystemResource.FileSystemResource(String)
org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(Resource)
具体实现为:
Resource resource = new FileSystemResource("...");
Properties = PropertiesLoaderUtils.loadProperties(resource);
2.现在org.springframework.beans.factory.FactoryBean<T>接口的类,在获取bean时调用的是实现类的getObject()方法;
3.获取注解的对象:
org.springframework.beans.factory.ListableBeanFactory.getBeansWithAnnotation(Class<? extends Annotation>)
4.初始化bean和销毁bean之前要想执行特定的动作有如下三种方式:
第一种:通过@PostConstruct和@PreDestroy注解
第二种:通过在xml中bean上定义init-method和destory-method属性
第三种:通过实现InitializingBean和DisposableBean接口。
5.获取spring应用上下文的方法是实现ApplicationContextAware接口,重写setApplicationContext()方法
6.在spring容器启动时不能使用
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); wac.getBean(beanID);