用spring的InitializingBean的afterPropertiesSet初始化

Verilog三种赋值方式详解:从assign到always @(posedge clk)的硬件映射 在FPGA与数字IC设计中,Verilog HDL是描述硬件电路的核心语言。初学者常困惑于assign、always @(*)与always @(posedge clk)之间的区别——它们语法相近,却对应截然不同的硬件结构。本文从组合逻辑与时序逻辑的基本概念出发,剖析连续赋值、过程赋值与寄存器赋值的原理,阐明阻塞赋值与非阻塞赋值的本质差异。通过半加器、多路选择器、计数器等典型工程案例,梳理三种赋值方式在电路综合中的技术价值与应用场景,并总结出"三问五查"的RTL设计检查流程,帮助开发者建立从代码到电路的清晰 阅读详情

 

实例

 

@Component
public class NettyServer implements InitializingBean{
	@Resource
	private ChannelInitializer<SocketChannel> childHandler;
	@Value("${netty.host}")
	private String host;
	@Value("${netty.port}")
	private int port;
	public void afterPropertiesSet() throws Exception {
		System.out.println("server afterPropertiesSet");
		EventLoopGroup parentGroup = new NioEventLoopGroup(Runtime.getRuntime()
	            .availableProcessors() * 2);
		EventLoopGroup childGroup = new NioEventLoopGroup(Runtime.getRuntime()
	            .availableProcessors() * 2);
		ServerBootstrap server = new ServerBootstrap();
		server.group(parentGroup, childGroup);
		server.channel(NioServerSocketChannel.class);
		server.childHandler(childHandler);
		server.bind(new InetSocketAddress(host, port)).sync();
	}
	public void setChildHandler(ChannelInitializer<SocketChannel> childHandler) {
		this.childHandler = childHandler;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public void setPort(int port) {
		this.port = port;
	}
	
	
}


参考

 

 

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接口就行。

 

 

SDU CS 期末考回忆版合集 删除原有分散的版本,合订起来画个。包括:机器学习、算法、图形学、操作系统、编译原理、软件工程、大数据分析管理、计算机体系结构等。 阅读详情

相关推荐

SageMath下载与安装

SageMath的下载与安装

旺旺的碎冰冰~的博客 7497

spring的InitializingBean的 afterPropertiesSet 方法

需要注意的是,虽然 InitializingBean 可以用于一些简单的初始化操作,但通常推荐使用更灵活的方式来完成 bean 的初始化,比如使用 @PostConstruct 注解或自定义的初始化方法。这样可以更好地控制 bean 的初始化过程,并提高代码的可读性和可维护性。举个例子,假设有一个名为 MyBean 的 bean 类,它实现了 InitializingBean 接口,可以在 afterPropertiesSet() 方法中添加一些初始化逻辑,比如初始化一些默认值或者建立与其他资源的连接。

weixin_52774180的博客 1570

Joern实战:从代码导入到Python分析的全流程避坑指南(附常见错误解决方案)

本文详细介绍了Joern静态分析工具从代码导入到Python分析的全流程实践指南,包括环境配置、代码导入技巧、数据库服务优化、Python交互分析及性能调优等关键步骤。特别针对常见错误提供了实用解决方案,帮助开发者高效进行代码安全分析和漏洞挖掘。

weixin_28309571的博客 140

InitializingBean初始化--Spring容器管理

InitializingBean初始化--Spring容器管理

beiback的博客 1921

手把手教你用STM32CubeMX配置I3C通信(含动态地址分配实战)

本文提供了一份基于STM32CubeMX配置I3C通信的实战指南,重点讲解了动态地址分配的实现步骤。通过详细的工程配置、从设备枚举、CCC命令使用及数据读写示例,帮助开发者快速掌握这一高效通信协议,以替代传统的I2C或SPI接口,满足多传感器连接与低功耗设计需求。

c8d9e0f1的博客 543

2d游戏地图编辑器_[U3D]基于MarchingCubes实现的War3Editor 地表/悬崖编辑器

花了几天时间研究清楚Marching cubes后,发现这个方法是一个非常适用于地图编辑,网格编辑,procedural 生成的工具。最大的优点有着较好的边缘,表面处理。然后我用U3D写了一个悬崖/地表的编辑器。其中使用到了Marching Cubes的2.5D,2D两种降维的方法。talk is cheap,让我看效果!DemoEditor展示https://www.zhihu.com/vide...

weixin_42504649的博客 1178

Springboot扩展点系列_InitializingBean

到这里InitializingBean#afterPropertiesSet方法和init-method是什么时候开始调用,是用什么方式来调用的呢,已经分析清楚了,同时还了解到InitializingBean#afterPropertiesSet方法和init-method有类似的效果,执行时机也比较接近,但是是两个完全不同的东西,且InitializingBean#afterPropertiesSet方法的执行时机要稍早于init-method。是用什么方式来调用的呢?

皮球 791

ROM和RAM在单片机程序运行理解

ROM和RAM是电子设备中两种核心存储组件,主要区别在于:ROM用于长期存储系统程序、用户文件等固定数据,断电后数据不丢失,但写入速度较慢;RAM则用于临时存储运行中的程序和数据,读写速度快但断电后数据会清空。在单片机中,ROM存储程序代码和常量,RAM存储运行时的变量和数据。两者协同工作,ROM如同"永久档案库"保存必要信息,RAM则像"临时工作台"支持高速运算,共同确保设备正常运行。

qq_37999850的博客 1620

动态初始化类 InitializingBean 的 afterPropertiesSet方法

InitializingBean 的 afterPropertiesSet方法

一路向前 2425

《网络安全自学教程》- 802.1x协议

802.1x协议架构,工作原理/认证流程,认证方式,MAB认证,触发认证的三种方式,EAP报文格式,EAPOL报文格式

wangyuxiang946的博客 2万+

V90伺服 EPOS模式下回原(详细配置+SCL源代码)

/ 输出上限 100.0%rSetPoint : Real;// 设置目标值工程量。// 通道转换参考值。Td : Real;

RXXW_Dor的博客 2665

用spring的InitializingBean的afterPropertiesSet来初始化

org.springframework.beans.factory包下有一个接口是InitializingBean 只有一个方法: /**   * Invoked by a BeanFactory after it has set all bean properties supplied   * (and satisfied BeanFactoryAware and ApplicationC

牵挂著你是那颗我的心 飘呀飘地在你面前捉摸不定 牵挂著你是那份我的情 吹呀吹到你的眼前我的心 我不愿看到你那湿润的眼睛 怕我会忍不住疼你怕你伤心 我不愿听见你说寂寞的声音 怕我会忍不自你说我的真感情 9865

【unity实战】Unity2D TileMap的探究(最简单,最全面的TileMap使用介绍)

之前有人在微信上找我,问了TileMap相关的知识【unity实战】随机地下城生成2——绘制地图Tilemap的使用及一些技巧的使用(含源码)不过写的不是特别不是特别细致,只是简单的用了一下,所有这次特地打算单独写一篇文章,来介绍一下,下次还有人问我,我直接就把这篇文章丢给他,完美!Unity的Tilemap 一般称之为瓦片地图或者平铺地图,是 Unity2017 中新增的功能,主要用于快速编辑 2D 游戏中的场景,通过复用资源的形式提升地图多样性。Tilemap是一个用于创建2D地图的工具。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1万+

用spring的 InitializingBean 的 afterPropertiesSet 来初始化

void afterPropertiesSet() throws Exception; 这个方法将在所有的属性被初始化后调用。 但是会在init前调用。 但是主要的是如果是延迟加载的话,则马上执行。 所以可以在类上加上注解: import org.springframework.context.annotation.Lazy; @Lazy(fals...

360

深度学习工具包 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")

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【Spring容器管理】InitializingBean初始化,afterPropertiesSet,@PostConstruct 注解

InitializingBean 是 Spring 框架中的一个接口,用于在 Bean 初始化完成后执行特定的操作。它定义了一个方法 afterPropertiesSet(),当 Bean 的属性设置完成后会被调用。当一个 Bean 实现了 InitializingBean 接口,并且在配置文件中声明了该 Bean,Spring 容器会在实例化该 Bean 并设置完属性后,自动调用 afterPropertiesSet() 方法来执行一些初始化操作。这样可以避免在配置文件中手动调用初始化方法。

weixin_44823875的博客 3479

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

spring容器初始化过程笔记(四)InitializingBean 接口的 afterPropertiesSet 方法执行

这篇讲了spring源码InitializingBean接口的afterPropertiesSet方法执行描述,主要是对spring源码做笔记,需要读者下载spring源码编译执行辅助。

weixin_43064364的博客 2088

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

spring bean 三种初始化方法顺序(@PostConstruct,InitializingBean(afterPropertiesSet),@Bean(initMethod))

@PostConstruct注解标注的方法(JSR250) 实现InitializingBean接口的afterPropertiesSet方法(Spring的接口) 使用@Bean注解属性initMethod自定义的方法(Spring提供)

blog_zxb的博客 6087

使用spring的 InitializingBean 的 afterPropertiesSet 来初始化配置信息

一、在application.properties中配置信息 #配置阿里云OSS所需要的常量 aliyun.oss.file.endPoint=oss-cn-chengdu.aliyuncs.com aliyun.oss.file.accessKeyId=********************************* aliyun.oss.file.accessKeySecret=******************************* aliyun.oss.file.bucketName=***

qq_43194157的博客 593

Spring为bean提供了两种初始化bean的方式,实现InitializingBean接口里的afterPropertiesSet方法,或者在配置文件中通过init-method指定

配置文件 <bean id="testInitializingBean" class="com.TestInitializingBean" ></bean> Main函数如下 public class Main { public static void main(String[] args){ ApplicationContext context = new FileSystemXmlApplicationContext("/src/main/java/...

飞火龙在天的博客 522
上一篇: netty 连接 No buffer space available (maximum connections reached?): connect
下一篇: java开发守护进程
琅琊山二当家
博客等级 码龄18年 447粉丝 322原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值