@PostConstruct注解小结
1.在具体Bean的实例化过程中,@PostConstruct注解的方法,会在构造方法之后,init方法之前进行调用
2.在项目中@PostConstruct主要应用场景是在初始化Servlet时加载一些缓存数据等
举个例子,使用@PostConstruct注解:
Class ServiceA{
private Map<String, String> initMap;
//在这里加载一些缓存数据
@PostConstruct
public void init() {
initMap = new HashMap<>(3);
initMap.put("A","the a");
initMap.put("B","the b");
initMap.put("C","the c");
}
}
@PostConstruct注解小结的更多相关文章
- @PostConstruct 注解
@PostConstruct 注解 /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. ...
- springboot用@Autowired和@PostConstruct注解把config配置读取到bean变成静态方法
springboot用@Autowired和@PostConstruct注解把config配置读取到bean变成静态方法 @SpringBootApplication public class Sen ...
- 【spring源码分析】spring和@PostConstruct注解
@PostConstruct注解好多人以为是Spring提供的.其实是Java自己的注解. Java中该注解的说明:@PostConstruct该注解被用来修饰一个非静态的void()方法.被@Pos ...
- @PostConstruct和@PostConstruct 注解 及ehcache 缓存 执行过程 小记
@PostConstruct 和@PostConstruct 注解 从Java EE 5规范开始,Servlet中增加了两个影响Servlet生命周期的注解(Annotion):@PostConstr ...
- java的@PostConstruct注解
javax.annotation 注释类型 PostConstruct @Documented @Retention(value=RUNTIME) @Target(value=METHOD) publ ...
- Spring@PostConstruct注解和构造方法的调用顺序
先看下@PostConstruct的注解 * The PostConstruct annotation is used on a method that needs to be executed * ...
- @PostConstruct注解原理解析
所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 正文 @PostConstruct注解使用简介 在了解一个东西的原理之前,我们得初步的懂得如何 ...
- 【String注解驱动开发】你了解@PostConstruct注解和@PreDestroy注解吗?
写在前面 在之前的文章中,我们介绍了如何使用@Bean注解指定初始化和销毁的方法,小伙伴们可以参见<[Spring注解驱动开发]如何使用@Bean注解指定初始化和销毁的方法?看这一篇就够了!!& ...
- 【Java注解】@PostConstruct 注解相关
不多逼逼,直接看注解上面的文档, @PostConsturct PostConstruct注释用于需要执行的方法在依赖注入完成后执行任何初始化.这个方法必须在类投入服务之前调用. 这个所有支持依赖关系 ...
随机推荐
- 2019CVTE技术支持软件编程
题目:找出长度为M的数组S中求和为1的任意三个数组合个数,举例:S=[-2, 0, 1, 2, -1, 3],结果为:3个([-2, 0, 3], [-2, 1, 2], [0, 2, -1]). 思 ...
- C 一维数组 冒泡排序,查最大值
1. 初始化 char a[10] = {'1','2','3','4','5'};//指定数组大小并部分赋初值, 其余部分赋值 '\0' ,ASSIC 是 0 char b[] = {'1','2' ...
- 18.25 JLink调试程序步骤
S3C2440开发板启动时候选择NandFlash启动,然后输入如下命令: r /*复位cpu*/ h ...
- hanlp 加载远程词库示例
说明 ·目前的实现方式是以远程词库的内容重新构建CustomDictionary.trie,demo主要是为了实现同步远程词库,对性能暂不作考虑,对性能要求要以CustomDictionary.dat ...
- SoapUI测试WebService接口
Getting Started Getting started with some ad-hoc testing of a SOAP service is straight forward; se ...
- php商品对比功能代码分享
商品对比调用的JS文件(包含了商品对比框浮动JS): /*浮动窗口*/ (function(){ var n=10; var obj=document.getElementById(&qu ...
- 谈谈我对 js原型链的理解
想要学习 “原型链” 必须要认识什么是 “原型” 和 “原型链” 先理解一下普通的继承和原型的区别,下面写一段js代码来帮助理解: var Animal = function(){ // 动物抽象类 ...
- [蓝桥杯]PREV-19.历届试题_九宫重排
题目描述: 代码如下: #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1 ...
- shell脚本命令远程连接ssh并执行命令
环境: redhat 6.5 根据网上提供方法,测试了很多写法都不成功,测试了很久才有了以下脚本. 命令远程连接ssh并执行命令,scp/ftp等远程连接操作同理: #!/usr/bin/expect ...
- AX2012 ERP 维度相关表数据关系图
AX2012比AX2009可怜的几个维度来说,太丰富了,可以无数个啊.维度多了,如何使用以及管理是个问题.这个需要在做调研时,充分分析讨论确定.以下为维度表关联关系,在做SQL取值时需要了解下,比如在 ...