Spring (二)@Order, Ordered 失效

Spring (二)@Order, Ordered 失效

先上例子

public class OrderAnnotationExample {@Order(2)static class MyBeanFactoryPostProcessor1 implements BeanFactoryPostProcessor {@Overridepublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {System.out.println("MyBeanFactoryPostProcessor1");}}@Order(1)static class MyBeanFactoryPostProcessor2 implements BeanFactoryPostProcessor {@Overridepublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {System.out.println("MyBeanFactoryPostProcessor2");}}public static void main(String[] args) {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();context.register(MyBeanFactoryPostProcessor1.class, MyBeanFactoryPostProcessor2.class);context.refresh();}
}
> Task :spring-demo:OrderAnnotationExample.main()
MyBeanFactoryPostProcessor1
MyBeanFactoryPostProcessor2
public class OrderedInterfaceExample {static class MyBeanFactoryPostProcessor1 implements BeanFactoryPostProcessor, Ordered {@Overridepublic int getOrder() {return 2;}@Overridepublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {System.out.println("MyBeanFactoryPostProcessor1");}}static class MyBeanFactoryPostProcessor2 implements BeanFactoryPostProcessor, Ordered {@Overridepublic int getOrder() {return 1;}@Overridepublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {System.out.println("MyBeanFactoryPostProcessor2");}}public static void main(String[] args) {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();context.register(MyBeanFactoryPostProcessor1.class, MyBeanFactoryPostProcessor2.class);context.refresh();}
}
> Task :spring-demo:OrderedInterfaceExample.main()
MyBeanFactoryPostProcessor2
MyBeanFactoryPostProcessor1

BeanFactoryPostProcessor 文檔中有一句話

Factory hook that allows for custom modification of an application context’s bean definitions, adapting the bean property values of the context’s underlying bean factory.
Useful for custom config files targeted at system administrators that override bean properties configured in the application context. See PropertyResourceConfigurer and its concrete implementations for out-of-the-box solutions that address such configuration needs.
A BeanFactoryPostProcessor may interact with and modify bean definitions, but never bean instances. Doing so may cause premature bean instantiation, violating the container and causing unintended side effects. If bean instance interaction is required, consider implementing BeanPostProcessor instead.
Registration
An ApplicationContext auto-detects BeanFactoryPostProcessor beans in its bean definitions and applies them before any other beans get created. A BeanFactoryPostProcessor may also be registered programmatically with a ConfigurableApplicationContext.
Ordering
BeanFactoryPostProcessor beans that are autodetected in an ApplicationContext will be ordered according to org.springframework.core.PriorityOrdered and org.springframework.core.Ordered semantics. In contrast, BeanFactoryPostProcessor beans that are registered programmatically with a ConfigurableApplicationContext will be applied in the order of registration; any ordering semantics expressed through implementing the PriorityOrdered or Ordered interface will be ignored for programmatically registered post-processors. Furthermore, the @Order annotation is not taken into account for BeanFactoryPostProcessor beans.

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/160233.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/160233.shtml
英文地址,請注明出處:http://en.pswp.cn/news/160233.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何加速JavaScript 代碼運行速度

如何加速JavaScript 代碼運行速度 前言減少DOM訪問避免不必要的變量延遲script加載異步和同步使用異步編程避免使用With關鍵詞 前言 本文主要通過五個方面來講解如何使Js代碼得到性能優化,從而實現加快Js代碼運行速度的作用。那么好,本文正式開始。 減…

感染了后綴為.[bkpsvr@firemail.cc].EKING勒索病毒如何應對?數據能夠恢復嗎?

導言: 在當前數字時代,勒索病毒成為網絡威脅的一大隱患。本文將深入介紹一種名為[bkpsvrfiremail.cc].EKING的勒索病毒,以及如何應對遭受其攻擊后,有效地恢復被加密的數據文件,并提供一些預防措施以減少感染的風險。數…

sqlserver==索引解析,執行計劃,索引大小

1創建測試表 -- 創建大型表 CREATE TABLE LargeTableWithIndex (ID int IDENTITY(1,1) PRIMARY KEY,IndexedColumn int,NonIndexedColumn nvarchar(255),OtherData nvarchar(255) );2插入測試數據 -- 使用 T-SQL 插入大量數據 DECLARE @i int = 1; WHILE @i <= 100000 -- …

Mac中LaTex無法編譯的問題

最近在使用TexStudio時&#xff0c;遇到一個棘手的問題&#xff1a; 無法編譯&#xff0c;提示如下&#xff1a; kpathsea: Running mktexfmt xelatex.fmt /Library/TeX/texbin/mktexfmt: kpsewhich -var-valueTEXMFROOT failed, aborting early. BEGIN failed–compilation a…

[Linux] Network: IPv6 link-local 地址是否可用不自動生成

原來有一段時間在做擴充產品的VLAN個數&#xff0c;然后就遇到過一個問題&#xff1a;說這個Linux的默認配置里&#xff0c;會為每一個網絡接口添加一個link-local的地址&#xff0c;就是FE80::開頭的地址&#xff0c;在RFC-4291里有如下的定義&#xff1a; Link-Local unicas…

redis運維(十二) 位圖

一 位圖 ① 概念 1、說明&#xff1a;位圖還是在操作字符串2、位圖玩字符串在內存中存儲的二進制3、ASCII字符通過映射轉化為二進制4、操作的是字符串value ② ASCII字符鋪墊 1、控制ASCII字符 2、ASCII可顯示字符 ③ SETBIT 細節&#xff1a; setbit 命令的返回值是之…

git常用命令(git github ssh)

目錄 1、語法說明2、本地倉庫相關操作建立一個git文件(git init)把工作區的文件添加到暫存區(git add)把暫存區的文件添加到本地倉庫(git commit)查看暫存區和本地倉庫中的文件(git ls-files)查看文件夾下所有文件的狀態(git status)查看版本庫中的提交記錄(git log)恢復的文件…

如何解決msvcp110.dll丟失問題,分享5個有效的解決方法

最近&#xff0c;我在使用電腦時遇到了一個令人頭疼的問題——msvcp110.dll丟失。這個錯誤通常會導致某些應用程序無法正常運行。為了解決這個問題&#xff0c;我們需要采取一些有效的方法來修復丟失的msvcp110.dll文件。那么&#xff0c;msvcp110.dll到底是什么呢&#xff1f;…

代碼隨想錄 10.14 || 二叉樹 LeetCode 669.修剪二叉搜索樹、108.將有序數組轉換為二叉搜索樹、538.將二叉搜索樹轉為累加樹

669.修剪二叉搜索樹 根據給定的最小邊界 left 和最大邊界 right 修剪二叉搜索樹&#xff0c;保留值在 left ~ right 的節點&#xff0c;刪除不滿足此條件的節點。修剪樹不應該改變保留在樹中的元素的相對結構&#xff0c;即父子關系。 設 cur 為當前訪問的二叉樹節點&#xff0…

LeetCode(32)串聯所有單詞的子串【滑動窗口】【困難】(含圖解)

目錄 1.題目2.答案3.提交結果截圖4.圖解 鏈接&#xff1a; 串聯所有單詞的子串 1.題目 給定一個字符串 s 和一個字符串數組 words。 words 中所有字符串 長度相同。 s 中的 串聯子串 是指一個包含 words 中所有字符串以任意順序排列連接起來的子串。 例如&#xff0c;如果 w…

Flutter的Event Loop

Flutter 的事件循環機制是其框架的核心部分&#xff0c;它負責管理事件的處理和UI的渲染。了解這個機制對于開發高效且響應迅速的Flutter應用非常重要。以下是Flutter事件循環的主要組成部分和工作原理&#xff1a; 1. 主事件循環&#xff08;Main Event Loop&#xff09; 當…

利用ros實現單片機通訊(轉載)

我覺得如果使用這個人的micro_ros通信協議&#xff0c;就不用再去Ubuntu或者Windows上面自己寫驅動程序了&#xff0c; 利用micro_ros實現esp32與ros2的通訊 Tianci ? 天津大學 工學博士 參考&#xff1a;https://github.com/micro-ROS/micro_ros_arduino https://blog.cs…

B站app作品列表sign

之前寫過一篇pc的:B站pc端w_rid逆向 最近pc端老是作妖,更新的太頻繁了, 于是決定干一下app, pc端有個w_rid加密,app端也有個類似的sign 人狠話不多,直接上成果吧: # -*- coding: UTF-8 -*- import hashlib import time import requests import json from urllib.parse…

C語言好好題(一維數組)

兩天沒有更新了&#xff0c;貼紙們&#xff0c;有沒有想我呀。&#x1f604;&#x1f604;&#x1f604; 好了&#xff0c;就寒暄到這里吧&#xff0c;下面請看題&#xff1a; 有序序列判斷 輸入一個整數序列&#xff0c;判斷是否是有序序列&#xff0c;有序&#xff0c;指序列…

騰訊云輕量4核8G12M帶寬服務器租用價格和S5實例報價

騰訊云4核8G服務器優惠價格表&#xff0c;云服務器CVM標準型S5實例4核8G配置價格15個月1437.3元&#xff0c;5年6490.44元&#xff0c;輕量應用服務器4核8G12M帶寬一年446元、529元15個月&#xff0c;阿騰云atengyun.com分享騰訊云4核8G服務器詳細配置、優惠價格及限制條件&…

C++(模板進階)

目錄 前言&#xff1a; 本章學習目標&#xff1a; 1.非類型模版參數 1.1使用方法 1.2注意事項 1.3 實際引用 2.模版特化 2.1概念 2.2函數模板特化 2.3類模板特化 2.3.1全特化 2.3.2偏特化 3.模版分離編譯 ?編輯 3.1失敗原因 ?編輯 3.2解決方案 4 總結 前言&…

【C++】類和對象——構造函數和析構函數

今天要學習兩個特殊的函數&#xff0c;分別是構造函數和析構函數&#xff0c;它們究竟有什么用呢&#xff1f; 比如說&#xff0c;我們先寫一個簡單的日期的類 class Date { public:void Init() {_year 1;_month 1;_day 1;}void Print() {cout << _year << &qu…

Sentinel 分布式系統

Sentinel 是一種分布式系統的流量防衛兵和熔斷器&#xff0c;由阿里巴巴開發并開源。它的主要目標是保護分布式系統中的穩定性和可用性&#xff0c;防止因高并發或異常流量而導致的系統崩潰。下面是 Sentinel 的原理和使用教程的概要&#xff1a; Sentinel 的原理&#xff1a;…