用spring的InitializingBean作初始化
org.springframework.beans.factory包下有一个接口是InitializingBean 只有一个方法:
/**
  * Invoked by a BeanFactory after it has set all bean properties supplied
  * (and satisfied BeanFactoryAware and ApplicationContextAware).
  * <p>This method allows the bean instance to perform initialization only
  * possible when all bean properties have been set and to throw an
  * exception in the event of misconfiguration.
  * @throws Exception in the event of misconfiguration (such
  * as failure to set an essential property) or if initialization fails.
  */
 void afterPropertiesSet() throws Exception;
这个方法将在所有的属性被初始化后调用。
但是会在init前调用。
但是主要的是如果是延迟加载的话,则马上执行。
所以可以在类上加上注解:
import org.springframework.context.annotation.Lazy;
@Lazy(false)
这样spring容器初始化的时候afterPropertiesSet就会被调用。
只需要实现InitializingBean接口就行。
用spring的InitializingBean作初始化的更多相关文章
- Spring管理的bean初始化方法的三种方式,以及@PostConstruct不起作用的原因
		1:Spring 容器中的 Bean 是有生命周期的,spring 允许 Bean 在初始化完成后以及销毁前执行特定的操作.下面是常用的三种指定特定操作的方法: 通过实现InitializingBea ... 
- spring扩展点之二:spring中关于bean初始化、销毁等使用汇总,ApplicationContextAware将ApplicationContext注入
		<spring扩展点之二:spring中关于bean初始化.销毁等使用汇总,ApplicationContextAware将ApplicationContext注入> <spring ... 
- 十二、Spring之IOC容器初始化
		Spring之IOC容器初始化 前言 在前面我们分析了最底层的IOC容器BeanFactory,接着简单分析了高级形态的容器ApplicationContext,在ApplicationContext ... 
- Spring IoC bean 的初始化
		前言 本系列全部基于 Spring 5.2.2.BUILD-SNAPSHOT 版本.因为 Spring 整个体系太过于庞大,所以只会进行关键部分的源码解析. 本篇文章主要介绍 Spring IoC 容 ... 
- spring自动扫描、DispatcherServlet初始化流程、spring控制器Controller 过程剖析
		spring自动扫描1.自动扫描解析器ComponentScanBeanDefinitionParser,从doScan开始扫描解析指定包路径下的类注解信息并注册到工厂容器中. 2.进入后findCa ... 
- Spring IoC容器的初始化过程
		Spring IoC容器的初始化包括 BeanDefinition的Resource定位.载入和注册 这三个基本的过程.IoC容器的初始化过程不包含Bean依赖注入的实现.Bean依赖的注入一般会发生 ... 
- spring internalTransactionAdvisor 事务 advisor 初始化过程
		spring internalTransactionAdvisor 事务 advisor 初始化过程: 
- 工厂模式-Spring的InitializingBean实现
		一.创建产品角色接口: package org.burning.sport.design.pattern.factorypattern.spring.factory; public interface ... 
- Spring MVC之DispatcherServlet初始化详解
		Spring作为一个优秀的web框架,其运行是基于Tomcat的.在我们前面的讲解中,Spring的驱动都是使用的ClassPathXmlApplicationContext,并且都是直接在main方 ... 
随机推荐
- Sublime Text3 常用快捷键
			1. 更改变量名的几种方法 a.选中变量,ctrl+d 一个个选择 b.选中变量,alt+F3 2.查找打开过的文件:Ctrl+P,然后输入最近的文件名就可以即时预览到文件内容. 3.ctrl+r ... 
- 读源码之RESideMenu
			RESideMenu是github上比较出名的一个开源库,主要是实现侧滑菜单,现在有三千多个star了.效果如下. 据说创意来源于dribbble的一个设计,还是比较好看的.感兴趣的可以去gith ... 
- MVC中的模型
			为MVC Music Store 建模 建模代码: public class Album { public virtual int AlbumId { get; set; } public virtu ... 
- 使用maven来管理您的java项目
			maven是一个项目管理工具,使用maven可以自动管理java项目的整个生命周期,包括编译.构建.测试.发布和报告等.在大型项目开发中,使用maven来管理是必不可少的. 一.安装maven 1.W ... 
- oracle数据导出工具sqluldr2
			oracle数据导出工具sqluldr2可以将数据以csv.txt等格式导出,适用于大批量数据的导出,导出速度非常快.导出后可以使用oracle loader工具将数据导入.下载完sqluldr2,工 ... 
- mysql   apache  php   install
			设置LINUX自动匹配环境变量 1.$su #su进入root #vi /etc/profile 在文件末尾加上下列语句: PATH=$PATH:/sbin #在PATH变量后追加/sbin目录 ex ... 
- struts2-通配符映射(基本没啥卵用)和动态调用
			通配符 使用*代表任意字符 一般在action的name中使用*,并可以使用多个 可以使用{通配符的序号}引用对应的通配符所代表的值,序号从1开始 {0}代表整个URI 匹配规则 首先完全匹配,没有完 ... 
- 【转】[退役]纪念我的ACM——headacher@XDU
			转自:http://hi.baidu.com/headacher/item/5a2ce1d50609091b20e25022 退役了,是时候总结一下我ACM的生涯了.虽然很舍不得,但这段回忆很值得纪念 ... 
- 用hashMAP或ArrayList解决recylerView中checkbox的选择错乱问题。
			//这个监听一定要放在checkbox初始化的方法之前,否则无效.是因为滑动的时侯会重新给checkbox赋值造成的.holder.cbFileSel.setOnCheckedChangeListen ... 
- WampServer中MySQL中文乱码解决
			1.修改mysql的my.ini文件: 在 [client] 下面增加 default-character-set=utf8 在 [mysqld] 下面增加: character_set_server ... 
