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作初始化的更多相关文章

  1. Spring管理的bean初始化方法的三种方式,以及@PostConstruct不起作用的原因

    1:Spring 容器中的 Bean 是有生命周期的,spring 允许 Bean 在初始化完成后以及销毁前执行特定的操作.下面是常用的三种指定特定操作的方法: 通过实现InitializingBea ...

  2. spring扩展点之二:spring中关于bean初始化、销毁等使用汇总,ApplicationContextAware将ApplicationContext注入

    <spring扩展点之二:spring中关于bean初始化.销毁等使用汇总,ApplicationContextAware将ApplicationContext注入> <spring ...

  3. 十二、Spring之IOC容器初始化

    Spring之IOC容器初始化 前言 在前面我们分析了最底层的IOC容器BeanFactory,接着简单分析了高级形态的容器ApplicationContext,在ApplicationContext ...

  4. Spring IoC bean 的初始化

    前言 本系列全部基于 Spring 5.2.2.BUILD-SNAPSHOT 版本.因为 Spring 整个体系太过于庞大,所以只会进行关键部分的源码解析. 本篇文章主要介绍 Spring IoC 容 ...

  5. spring自动扫描、DispatcherServlet初始化流程、spring控制器Controller 过程剖析

    spring自动扫描1.自动扫描解析器ComponentScanBeanDefinitionParser,从doScan开始扫描解析指定包路径下的类注解信息并注册到工厂容器中. 2.进入后findCa ...

  6. Spring IoC容器的初始化过程

    Spring IoC容器的初始化包括 BeanDefinition的Resource定位.载入和注册 这三个基本的过程.IoC容器的初始化过程不包含Bean依赖注入的实现.Bean依赖的注入一般会发生 ...

  7. spring internalTransactionAdvisor 事务 advisor 初始化过程

    spring internalTransactionAdvisor 事务 advisor 初始化过程:

  8. 工厂模式-Spring的InitializingBean实现

    一.创建产品角色接口: package org.burning.sport.design.pattern.factorypattern.spring.factory; public interface ...

  9. Spring MVC之DispatcherServlet初始化详解

    Spring作为一个优秀的web框架,其运行是基于Tomcat的.在我们前面的讲解中,Spring的驱动都是使用的ClassPathXmlApplicationContext,并且都是直接在main方 ...

随机推荐

  1. angularJs非空校验requied

    <!DOCTYPE html><html><head><meta charset="utf-8"><title>< ...

  2. 白话学习MVC(七)Action的执行一

    一.概述 在此系列开篇的时候介绍了MVC的生命周期 , 对于请求的处理,都是将相应的类的方法注册到HttpApplication事件中,通过事件的依次执行从而完成对请求的处理.对于MVC来说,请求是先 ...

  3. [译]JavaScript规范-葵花宝典

    [译]JavaScript规范 译自:https://github.com/airbnb/javascript 类型 原始值: 相当于传值 string number boolean null und ...

  4. c#读取Word模板,利用书签替换内容包括表格

    //生成WORD程序对象和WORD文档对象 Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Inter ...

  5. 获取图片中感兴趣区域的信息(Matlab实现)

    内容提要 如果一幅图中只有一小部分图像你感兴趣(你想研究的部分),那么截图工具就可以了,但是如果你想知道这个区域在原图像中的坐标位置呢? 这可是截图工具所办不到的,前段时间我就需要这个功能,于是将其用 ...

  6. 配置MyBatis

    创建WebProject之后先把mybatis-3.2.2.zip里的mybatis-3.2.2.jar包和lib里的asm-3.3.1.jar.cglib-2.2.2.jar.commons-log ...

  7. Linux系统巡检常用命令

    # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # hostn ...

  8. 6.能够使HTML和PHP分离开使用的模板

    Smarty,Dwoo,TinyButStrong,Template Lite,Savant,phemplate,XTemplate

  9. OnScrollListener分页加载

    scrollState有三种状态,分别是SCROLL_STATE_IDLE.SCROLL_STATE_TOUCH_SCROLL.SCROLL_STATE_FLING    *SCROLL_STATE_ ...

  10. <c:if>标签判断是否为空

    <c:if test="${not empty feeType}">  注意:大括号外面不能为空. ${orderNo.ethdOriginalOrderNo} < ...