用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方 ...
随机推荐
- 解决ssh登录后闲置时间过长而断开连接
++++++++++++++++++++++++++++ #!/usr/bin/env bash password_5="Uxxx7"host_5="129.x.x.1 ...
- MySQL主键删除/添加
2修改数据库和表的字符集alter database maildb default character set utf8;//修改数据库的字符集alter table mailtable defaul ...
- JavaAPI_01
>JavaAPI 文档注释可以在:类,常量,方法上声明 文档注释可以被javadoc命令所解析并且根据内容生成手册 package cn.fury.se_day01; /** * 文档注释可以在 ...
- JQuery对象操作支持链式法则源码分析
JQuery链式法则 何为链式法则?先给出非链式写法的例子 //非链式写法 $("div").css("width", 45px); $("div&q ...
- JavaScript模块化开发整理
在网上已经有很多关于模块化开发的文章了,这里还是按照自己的理解来整理一下. 随着项目文件的越来越大和需求的越来越贴近现实(我发现现在客户不如:一个领导说我要审批你们报上来的资料,系统发布以后用的还不错 ...
- jquery通过name,id名称获取当前value值
name是input标签的属性值,jQuery提供了attr() 方法用于设置/改变属性值 $("input:text").attr("name");$(&qu ...
- vsftpd.conf Details
引用:http://blog.chinaunix.net/uid-23257894-id-2466823.html /etc/vsftpd/vsftpd.conf文件详解,分好类,方便大家查找与学习 ...
- 在linux中安装adb和fastboot工具
我用的是archlinux,在官方的软件仓库里就可以找到对应的包,包的名字叫:android-tools 据说debian系列的软件包是两个,分别是:android-tools-adb, androi ...
- C++中explicit关键字的作用
转载自:http://www.cnblogs.com/winnersun/archive/2011/07/16/2108440.html explicit用来防止由构造函数定义的隐式转换. 要明白它的 ...
- html5,output标签应用举例
<form action="" id="myform" oninput="num.value=parseInt(num1.value)+pars ...