Spring Bean的初始化和销毁的几种方式总结

最全Spring初始化Bean的方法 阅读详情

作为一个 Java 程序员 Spring 框架在我们日常工作和面试中可谓必不可少,学习和掌握好 Spring 对我们来说是很有必要的。

今天了不起就给大家介绍一下 Spring 的 Bean 的初始化和销毁的几种方式,看看你平时用的都是哪种。

初始化

由于 Spring Bean 的初始化都是 Spring 容器帮我们处理的,我们这里说的初始化是指在容器帮我们初始化的过程,我们有哪些方式可以进行手动干预,或者说初始化的时候如何运行我们自己的逻辑。

废话不多说,我们依次来看下面的几种方式

实现InitializingBean接口

我们可以写一个类,然后实现 InitializingBean 接口,通过覆盖其中的 afterPropertiesSet() 方法来实现我们自己的逻辑,我们写一个 case 来实现一下,如下所示

package com.example.demo.service;

import org.springframework.beans.factory.InitializingBean;

public class InitServiceImpl implements InitializingBean {
  private String name;
  @Override
  public void afterPropertiesSet() throws Exception {
    System.out.println("afterPropertiesSet...");
    this.name = "Java极客技术 afterPropertiesSet";
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}

实现的方式很简单,直接实现 org.springframework.beans.factory.InitializingBean 这个接口然后覆盖 afterPropertiesSet 这个方法即可,在这个方法里面,我们就可以执行我们需要在初始化时候就执行的代码。

比如这里我们在初始化方法里面直接给一个属性进行赋值,后续就可以直接使用了,如下所示

package com.example.demo.controller;

@RestController
public class HelloController {

  @Autowired
  InitServiceImpl initService;

  @GetMapping(value = "/hello")
  public String hello(@RequestParam String name) {
    return initService.getName();
  }
}

可以看到是可以直接获取到属性值的,这个比较简单我们就不赘述了,继续看下面两个方式。

增加 @PostConstruct 注解

我们继续在 InitServiceImpl 类中增加一个方法,并且在方法上面增加 @PostConstruct 注解,如下所示

  @PostConstruct
  public void postConstruct() {
    System.out.println("postConstruct...");
    this.name = "Java极客技术 postConstruct";
  }

这种写法比实现一个接口要简单一点,毕竟只要增加一个注解就行了,而不需要覆盖接口的方法,不过本质上没什么区别。

自定义init方法

这种方式也很简单,只不过我们做两个动作,第一个是在 InitServiceImpl 类中增加一个自定义的方法,方法内容如下,

  public void initMethod() {
    System.out.println("initMethod...");
    this.name = "Java极客技术 initMethod";
  }

然后再写一个配置类,在配置类中定义一个方法,在方法上面增加一个 @Bean 注解,并且赋值一个 init-method 方法,同时这个方法需要创建对象并返回,如下所示

package com.example.demo.service;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Config {

  @Bean(initMethod = "initMethod")
  public InitServiceImpl initServiceImpl() {
    return new InitServiceImpl();
  }
}

怎么样是不是也很简单。

小结

在这里问大家一个问题,如果我们在同一个类中同时存在这三种初始化方法,那会是什么情况呢?

我们来试一下就知道了,通过完整的代码,我们将三种方式都写进来,然后启动服务。

package com.example.demo.service;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;

public class InitServiceImpl implements InitializingBean {
  private String name;

  @Override
  public void afterPropertiesSet() throws Exception {
    System.out.println("afterPropertiesSet...");
    this.name = "Java极客技术 afterPropertiesSet";
  }

  @PostConstruct
  public void postConstruct() {
    System.out.println("postConstruct...");
    this.name = "Java极客技术 postConstruct";
  }

  public void initMethod() {
    System.out.println("initMethod...");
    this.name = "Java极客技术 initMethod";
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}

可以看到,我们的服务是正常的启动和运行,并且三个方法都正常的执行了,执行的顺序依次是 postConstruct,afterPropertiesSet,initMethod,那么这里问一下小伙伴们,此时我们的 name 值是什么呢?

销毁

既然我们初始化有三种形式,可以很自然的想到销毁是不是也有三种形式呢?没错,销毁的三种方法,也是跟上面类似,分别是

  1. 实现 org.springframework.beans.factory.DisposableBean 接口,覆盖 destroy() 方法;
  2. 自定义一个方法,在方法上面增加 @PreDestroy 注解;
  3. 在 InitServiceImpl 中增加一个自定义销毁方法,然后在配置类中增加 Bean 的 destoryMethod;

相关的内容也比较简单,在上面的 InitServiceImpl 和 Config 基础上只要增加一点点内容就好了

public class InitServiceImpl implements InitializingBean, DisposableBean {

  public void destroyMethod() throws Exception {
    System.out.println("destroyMethod...");
  }

  @Override
  public void destroy() throws Exception {
    System.out.println("destroy...");
  }

  @PreDestroy
  public void preDestroy() throws Exception {
    System.out.println("preDestroy...");
  }
}

  @Bean(initMethod = "initMethod", destroyMethod = "destroyMethod")
  public InitServiceImpl initServiceImpl() {
    return new InitServiceImpl();

  }

销毁的三个方法在执行的时候也是有优先级的,依次是 preDestroy,destroy,destroyMethod。

至此完整的一个包含三个初始化和三个销毁方法的代码就完成了,我们来运行一下看看整体的流程。

总结

虽然说 Spring 给我们提供了三种初始化和三种销毁的方法,不过我们在日常的写代码中很少会把三种都写上,但是对于这几种的优先级还是有必要了解的,万一别人给你挖坑了怎么办呢?

好了,今天了不起给大家介绍了一下 Spring 的三种初始化和三种销毁对象的方式,并且通过示例案例给大家介绍了一下优先级,希望对大家有帮助。

Zynq远程更新程序实战:从emmc到flash的完整方案解析 本文详细解析了Zynq远程更新程序的完整方案,重点探讨了从emmc到flash的实战操作。通过硬件连接限制破解、emmc配置技巧、flash擦写策略优化等关键技术点,提供了可靠的远程更新解决方案,特别适合需要频繁更新boot.bin的应用场景。 阅读详情

相关推荐

mtk-drm初始化

mtk-drm初始化走读

zhexingsunba的博客 4950

[源码系列:手写spring] IOC第十节:bean的初始化和销毁方法

自动注册的beanDefinition工厂类添加方法,支持注册有销毁方法的bean(即继承自DisposableBean或有自定义的销毁方法并在xml定义的Bean。当用户没有实现DisposableBean接口但是注册了自己的销毁方法在xml时,将利用此方法将beanDefinition中的方法名称提取,通过上面定义的DisposableBeanAdapter的方式在创建bean的时候存入单例beanFactory的容器中。...try {//填充属性。

一辉的博客 745

电源完整性仿真流程梳理

可根据仿真流程导图,一步一步的去设置完成仿真。仿真的关键,在于对电路回路的理解以及所放置的电压源与电流的合理性,对于去耦电容的选择,则需要根据谐振频率计算,从而选取有效滤波的容值。

csy17729158342的博客 3456

Spring Bean的初始化和销毁的几种方式,你一般用的是哪种?

作为一个 Java 程序员 Spring 框架在我们日常工作和面试中可谓必不可少,学习和掌握好 Spring 对我们来说是很有必要的。 今天了不起就给大家介绍一下 Spring 的 Bean 的初始化和销毁的几种方式,看看你平时用的都是哪种。

Javatutouhouduan的博客 651

Zemax操作16--激光谐振腔(含晶体)

谐振腔(含晶体)

lzy750750的博客 8343

第4章 Stata参数检验

目录 4.1单一样本T检验 案例延伸 4.2独立样本T检验 案例延伸 1.改变置信水平 2.在异方差假定条件下进行假设检验 4.3配对样本T检验 案例延伸 1.改变置信水平 4.4单一样本方差的假设检验 案例延伸 4.5双样本方差的假设检验 参数检验(Parameter Test)是指对参数的平均值、方差、比率等特征进行的统计检验。参数检验一般假设统计总体的具体分布为已知,但是其中一些参数或者取值范围不确定,分析的主要目的是估计这些未知参数的取值,或者对这些参数进...

qq_45112156的博客 1万+

spring手动初始化bean

ApplicationContext ctx= new ClassPathXmlApplicationContext(new String[]{“beans.xml”,”application.xml”});   BeanFactory  factory =ctx;

大道至简 分而治之 2762

AltiumDesigner相同模块复用操作

AltiumDesigner相同模块复用操作框选已布局好的A电路,作为复用模块创建Room同样的操作,框选C电路,然后也创建Room查看A电路的Chanel Offset显示设置复制Channel Offset查看B电路的Channel Offset复制A电路的Channel Offset到C电路Room格式的复制 框选已布局好的A电路,作为复用模块 创建Room 同样的操作,框选C电路,然后也创建Room 查看A电路的Chanel Offset 框选A模块的,然后点右下角的菜单——PCB——PCB

weixin_41947101的博客 5971

Spring中Bean的初始化及销毁方式

Spring中Bean的两种初始化方式是什么为什么但是,如果必须要用多例Bean怎么办?以下为Spring中的多例及初始化再来说说初始化的一些不同细节问题:对Bean的销毁,也就是对容器的销毁 是什么 Spring中的Bean是由IoC容器来管理,这些Bean在同一个容器中是单例模式的,也就是说为无状态的。 这个单例不同于自己写的单例模式: 自己写的单例,从加载来说是通过ClassLoader加...

Joe_owl的专栏 602

s8654

The official Snapdragon Ride SX 4.0 development board provides standardized hardware support for the secondary development and functional verification of the s8654 platform.

qq_39257814的博客 6847

借助AI高效写出结构严谨、内容专业的课题申报书:10大核心模块拆解(附实用提示词)

在很多老师和科研人员眼中,写一份高质量的课题申报,确实是一件非常困难的事。难就难在不只是要说清楚写了什么研究内容,还要体现申报书的可行性和创新性。七哥除了自己写课题,也经常指导会员同仁使用高级学术版搞定课题的申报工作,摸索出了一套行之有效的借助AI申报课题的技巧,在这篇文章中,我将给大家点明课题申报书的10大核心模块的写作技巧,还会给大家一些提示词模板供大家参考,如果你也正准备申报课题,那么这篇文章一定不要错过!特别说明的是,提示词的使用并不是一蹴而就的,是专业思考的延伸和AI化专业表达,过程中需要多次的调

智能AI让学术科研更容易 466

Spring中bean的初始化和销毁几种实现方式详解

Bean的生命周期 : 创建bean对象 – 属性赋值 – 初始化方法调用前的操作 – 初始化方法 – 初始化方法调用后的操作 – ….– 销毁前操作 – 销毁方法的调用。 【1】init-method和destroy-method 两种方式,xml配置和注解。 ① xml配置: <bean id="person" class=&a

小小默:进无止境 2万+

matlab电子科技大学数学实验期末模拟35道(1)

【代码】matlab电子科技大学数学实验期末模拟35道。

c_wrj_的博客 2047

盘点Spring的Bean的初始化和销毁的几种方式

作为一个 Java 程序员 Spring 框架在我们日常工作和面试中可谓必不可少,学习和掌握好 Spring 对我们来说是很有必要的。

Javatutouhouduan的博客 376

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java bean初始化方法,Spring中bean的初始化和销毁几种实现方式详解

Bean的生命周期 : 创建bean对象 – 属性赋值 – 初始化方法调用前的操作 – 初始化方法 – 初始化方法调用后的操作 – …-- 销毁前操作 – 销毁方法的调用。【1】init-method和destroy-method自定义初始化方法和销毁方法两种方式:xml配置和注解。① xml配置class="com.core.Person" scope="singleton"init-metho...

weixin_31592801的博客 1218

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Spring中Bean的几种实现初始化(或销毁)的方式及其执行顺序

声明:本文测试环境为SpringBoot。 提示:本文以图片说明为主,文字版的测试代码,可见文末的代码托管链接。 有时,我们需要在bean创建后(或者bean销毁前),做一些事情,方式方法有很多,下面介绍如何通过【初始化/销毁相关方法】来达到我们的目的。 常用初始化后(或销毁前)做逻辑的方式: 实现InitializingBean接口、DisposableBean接口。 ...

JustryDeng 1113

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Spring bean初始化与销毁的几种方式和区别

1. <bean> 元素的 init-method/destroy-method属性指定初始化之后 /销毁之前调用的操作方法 2. 指定方法上加上@PostConstruct 或@PreDestroy注解来制定该方法是在初始化之后还是销毁之前调用 3. 通过实现 InitializingBean/DisposableBean 接口来定制初始化之后/销毁之前的操作方法 初始化 ...

weixin_30788619的博客 93

spring xml配置初始化执行方法_Spring注解设置Bean的初始化、销毁方法的方式,你知道几种?...

bean的生命周期:创建---初始化---销毁。Spring中声明的Bean的初始化和销毁方法有3种方式:1. @Bean的注解的initMethod、DestroyMethod属性2. bean实现InitializingBean、DisposableBean接口3. @PostConstruct、@PreDestroy注解4. BeanPostProcessor(这种仅仅增强了Bean的初始化...

weixin_39697660的博客 566

Spring学习----------(7)bean的声明周期,bean初始化,销毁的几种方式

首先说一下Spring Bean的生命周期.Spring Bean的生命周期分为四个阶段 实例化 -> 属性赋值 -> 初始化 -> 销毁 这四个阶段可以细化为为: 创建bean对象 -> 属性赋值 -> 初始化方法调用前的操作 -> 初始化方法 -> 初始化方法调用后的操作 ->… ->销毁前操作 -> 销毁方法的调用 实例化...

deram_strong的博客 387

Spring IOC之对象的创建方式、策略及销毁时机和生命周期且获取方式

Spring IOC之对象的创建方式、策略及销毁时机和生命周期且获取方式

qq_53317005的博客 4916

Bean的生命周期相关

前言: 前面一篇博客初步介绍了@Configuration + @Bean 的用法,这里简单总结下Spring容器中 bean 的生命周期(毕竟以前是自己各种 new 对象,现在大多交由容器帮我们管理)。 正文: 1、bean 的生命周期主要分为三个阶段:创建、初始化和销毁 创建: 单实例:在容器启动的时候就会创建bean;这也是后文提到 @Lazy 注解帮忙解决的问题 多实例:在getBean...

demon_2018的博客 243

Spring实战教程 | 第五篇:Spring自动装配及bean的生命周期

Spring自动装配 介绍 1、Spring IOC 容器可以自动装配 Bean. 需要做的仅仅是在 的 autowire 属性里指定自动装配的模式 2、byType(根据类型自动装配): 若 IOC 容器中有多个与目标 Bean 类型一致的 Bean. 在这种情况下, Spring 将无法判定哪个 Bean 最合适该属性, 所以不能执行自动装配. 3、byName(根据名称自动装配...

w 976

Spring中bean注入前后的一些操作:

InitializingBean 和 DisposableBean init-method 和 destroy-method @PostConstruct 和 @PreDestroy In Spring, InitializingBean and DisposableBean are two marker interfaces, a useful way for Spring to perf...

weixin_33937778的博客 137

关于spring 的bean 装配

1.单实例(缺省)与原型bean :   singleton 为true 单实例模式,通过getBean或者装配只能得到同一实例 singleton 为false 原型模式,请求bean返回不同实例 2.实例化时调用init-method, 删除实例之前调用destroy-method 3.

水寿的博客 226

【Spring高级】Bean的初始化和销毁有哪些方式

Spring中Bean的初始化和销毁有哪些方式

qq_43745578的博客 1905

Spring中Bean初始化和销毁的多种方式

详细介绍多种初始化Bean和销毁Bean的方式

初心不忘、始终方得 2481
上一篇: Java开发岗位供过于求,程序员被八股文还有用吗?
下一篇: 长达1.7万字的explain关键字指南奉上!SQL优化竟然如此简单?
Javatutouhouduan
博客等级 码龄4年 1105粉丝 958原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值