zoukankan      html  css  js  c++  java
  • 用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接口就行。

  • 相关阅读:
    Qt ini文件
    Qt我的文档 桌面路径
    windows zlib库编译步骤
    环形缓冲区
    openssl生成随机数
    怎样安装Scrapy
    CentOS7怎样安装GoAccess1.3
    Docker创建数据卷容器
    Docker创建数据卷
    Docker创建容器
  • 原文地址:https://www.cnblogs.com/jianwei-dai/p/6003766.html
Copyright © 2011-2022 走看看