spring——AOP原理及源碼(二)

来源:https://www.cnblogs.com/Unicron/archive/2020/03/03/12403620.html
-Advertisement-
Play Games

接下來我們就從後置處理器和BeanFactoryAware的角度來看看AnnotationAwareAspectJAutoProxyCreator的Bean定義類創建完成後都做了什麼。 ...


回顧:

上一篇中,我們提到@EnableAspectJAutoProxy註解給容器中加入了一個關鍵組件internalAutoProxyCreator的BeanDefinition,實際類型為

AnnotationAwareAspectJAutoProxyCreator的BeanDenation

並且發現這是一個後置處理器,也是一個XXXAware介面的實現類。以及探究了它的繼承關係如下。

 

 接下來我們就從後置處理器和BeanFactoryAware的角度來看看AnnotationAwareAspectJAutoProxyCreator的BeanDefinition創建完成後都做了什麼。


 

一、設置調試斷點

我們分別進入四個有關類,在類中與後置處理器和BeanFactoryAware有關的方法上打上斷點。最終效果如下:

AbstractAutoProxyCreator.setBeanFactory
AbstractAutoProxyCreator有後置處理器邏輯
{
  postProcessBeforeInstantiation()
  postProcessAfterInitialization()
}
AbstractAdvisorAutoProxyCreator.initBeanFactory
AbstractAdvisorAutoProxyCreator.setBeanFactory
AnnotationAwareAspectJAutoProxyCreator.initBeanFactory

最後,在配置類中給兩個bean方法打上斷點。



 

二、調試過程

開始調試,我們會發現還是先來到上一篇的AnnotationAwareAspectJAutoProxyCreator的BeanDenation創建過程。

左下角frames框中選到refresh方法可以看到,AnnotationAwareAspectJAutoProxyCreator的BeanDenation的創建是invokeBeanFactoryPostProcessors()方法調用來的。

調用這個方法在上下文中生成後置處理器的BeanDefinition加入容器中。

下一步的registerBeanPostProcessors才是註冊後置處理器(利用BeanDefinition的信息註冊對應Bean),也是本篇的重點。

 

為了讓它快速創建完BeanDefinition,這裡我們直接快進到下一個斷點。

程式先來到了AbstractAdvisorAutoProxyCreator的setBeanFactory方法

為了從頭看起,還是先在frames框中選到refresh方法,可以看到來到了refresh的下一方法,將要開始註冊後置處理器。


 

 

 二點一、registerBeanPostProcessors()

我們繼續在frames中往上點,直到來到PostProcessorRegistrationDelegate.registerBeanPostProcessors()

方法有點長,但關鍵只在其中幾個地方,我們將在下麵進行針對分析

 

 1 public static void registerBeanPostProcessors(
 2             ConfigurableListableBeanFactory beanFactory, AbstractApplicationContext applicationContext) {
 3 
 4         String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false);
 5 
 6         // Register BeanPostProcessorChecker that logs an info message when
 7         // a bean is created during BeanPostProcessor instantiation, i.e. when
 8         // a bean is not eligible for getting processed by all BeanPostProcessors.
 9         int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length;
10         beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory, beanProcessorTargetCount));
11 
12         // Separate between BeanPostProcessors that implement PriorityOrdered,
13         // Ordered, and the rest.
14         List<BeanPostProcessor> priorityOrderedPostProcessors = new ArrayList<BeanPostProcessor>();
15         List<BeanPostProcessor> internalPostProcessors = new ArrayList<BeanPostProcessor>();
16         List<String> orderedPostProcessorNames = new ArrayList<String>();
17         List<String> nonOrderedPostProcessorNames = new ArrayList<String>();
18         for (String ppName : postProcessorNames) {
19             if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
20                 BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
21                 priorityOrderedPostProcessors.add(pp);
22                 if (pp instanceof MergedBeanDefinitionPostProcessor) {
23                     internalPostProcessors.add(pp);
24                 }
25             }
26             else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
27                 orderedPostProcessorNames.add(ppName);
28             }
29             else {
30                 nonOrderedPostProcessorNames.add(ppName);
31             }
32         }
33 
34         // First, register the BeanPostProcessors that implement PriorityOrdered.
35         sortPostProcessors(priorityOrderedPostProcessors, beanFactory);
36         registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);
37 
38         // Next, register the BeanPostProcessors that implement Ordered.
39         List<BeanPostProcessor> orderedPostProcessors = new ArrayList<BeanPostProcessor>();
40         for (String ppName : orderedPostProcessorNames) {
41             BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
42             orderedPostProcessors.add(pp);
43             if (pp instanceof MergedBeanDefinitionPostProcessor) {
44                 internalPostProcessors.add(pp);
45             }
46         }
47         sortPostProcessors(orderedPostProcessors, beanFactory);
48         registerBeanPostProcessors(beanFactory, orderedPostProcessors);
49 
50         // Now, register all regular BeanPostProcessors.
51         List<BeanPostProcessor> nonOrderedPostProcessors = new ArrayList<BeanPostProcessor>();
52         for (String ppName : nonOrderedPostProcessorNames) {
53             BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
54             nonOrderedPostProcessors.add(pp);
55             if (pp instanceof MergedBeanDefinitionPostProcessor) {
56                 internalPostProcessors.add(pp);
57             }
58         }
59         registerBeanPostProcessors(beanFactory, nonOrderedPostProcessors);
60 
61         // Finally, re-register all internal BeanPostProcessors.
62         sortPostProcessors(internalPostProcessors, beanFactory);
63         registerBeanPostProcessors(beanFactory, internalPostProcessors);
64 
65         // Re-register post-processor for detecting inner beans as ApplicationListeners,
66         // moving it to the end of the processor chain (for picking up proxies etc).
67         beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));
68     }
registerBeanPostProcessors

4:獲取所有後置處理器的名字

14~32:對實現不同介面的後置處理器進行分類

35~48:對上面的分類分別進行處理,因為實現的是Ordered介面,我們只關註39~48行

 40~46:遍歷分好的實現了Ordered介面的後置處理器名,利用beanFactory.getBean(ppName, BeanPostProcessor.class)來獲取


 

 

二點二、doGetBean()

有了以上的步驟,我們主要來看beanFactory是怎麼獲取的

 

 可以看到,先來到了getBean方法,然後又進入了doGetBean方法。下麵我們來看doGetBean做了什麼。

  1 /**
  2      * Return an instance, which may be shared or independent, of the specified bean.
  3      * @param name the name of the bean to retrieve
  4      * @param requiredType the required type of the bean to retrieve
  5      * @param args arguments to use when creating a bean instance using explicit arguments
  6      * (only applied when creating a new instance as opposed to retrieving an existing one)
  7      * @param typeCheckOnly whether the instance is obtained for a type check,
  8      * not for actual use
  9      * @return an instance of the bean
 10      * @throws BeansException if the bean could not be created
 11      */
 12     @SuppressWarnings("unchecked")
 13     protected <T> T doGetBean(
 14             final String name, final Class<T> requiredType, final Object[] args, boolean typeCheckOnly)
 15             throws BeansException {
 16 
 17         final String beanName = transformedBeanName(name);
 18         Object bean;
 19 
 20         // Eagerly check singleton cache for manually registered singletons.
 21         Object sharedInstance = getSingleton(beanName);
 22         if (sharedInstance != null && args == null) {
 23             if (logger.isDebugEnabled()) {
 24                 if (isSingletonCurrentlyInCreation(beanName)) {
 25                     logger.debug("Returning eagerly cached instance of singleton bean '" + beanName +
 26                             "' that is not fully initialized yet - a consequence of a circular reference");
 27                 }
 28                 else {
 29                     logger.debug("Returning cached instance of singleton bean '" + beanName + "'");
 30                 }
 31             }
 32             bean = getObjectForBeanInstance(sharedInstance, name, beanName, null);
 33         }
 34 
 35         else {
 36             // Fail if we're already creating this bean instance:
 37             // We're assumably within a circular reference.
 38             if (isPrototypeCurrentlyInCreation(beanName)) {
 39                 throw new BeanCurrentlyInCreationException(beanName);
 40             }
 41 
 42             // Check if bean definition exists in this factory.
 43             BeanFactory parentBeanFactory = getParentBeanFactory();
 44             if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
 45                 // Not found -> check parent.
 46                 String nameToLookup = originalBeanName(name);
 47                 if (args != null) {
 48                     // Delegation to parent with explicit args.
 49                     return (T) parentBeanFactory.getBean(nameToLookup, args);
 50                 }
 51                 else {
 52                     // No args -> delegate to standard getBean method.
 53                     return parentBeanFactory.getBean(nameToLookup, requiredType);
 54                 }
 55             }
 56 
 57             if (!typeCheckOnly) {
 58                 markBeanAsCreated(beanName);
 59             }
 60 
 61             try {
 62                 final RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
 63                 checkMergedBeanDefinition(mbd, beanName, args);
 64 
 65                 // Guarantee initialization of beans that the current bean depends on.
 66                 String[] dependsOn = mbd.getDependsOn();
 67                 if (dependsOn != null) {
 68                     for (String dep : dependsOn) {
 69                         if (isDependent(beanName, dep)) {
 70                             throw new BeanCreationException(mbd.getResourceDescription(), beanName,
 71                                     "Circular depends-on relationship between '" + beanName + "' and '" + dep + "'");
 72                         }
 73                         registerDependentBean(dep, beanName);
 74                         getBean(dep);
 75                     }
 76                 }
 77 
 78                 // Create bean instance.
 79                 if (mbd.isSingleton()) {
 80                     sharedInstance = getSingleton(beanName, new ObjectFactory<Object>() {
 81                         @Override
 82                         public Object getObject() throws BeansException {
 83                             try {
 84                                 return createBean(beanName, mbd, args);
 85                             }
 86                             catch (BeansException ex) {
 87                                 // Explicitly remove instance from singleton cache: It might have been put there
 88                                 // eagerly by the creation process, to allow for circular reference resolution.
 89                                 // Also remove any beans that received a temporary reference to the bean.
 90                                 destroySingleton(beanName);
 91                                 throw ex;
 92                             }
 93                         }
 94                     });
 95                     bean = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);
 96                 }
 97 
 98                 else if (mbd.isPrototype()) {
 99                     // It's a prototype -> create a new instance.
100                     Object prototypeInstance = null;
101                     try {
102                         beforePrototypeCreation(beanName);
103                         prototypeInstance = createBean(beanName, mbd, args);
104                     }
105                     finally {
106                         afterPrototypeCreation(beanName);
107                     }
108                     bean = getObjectForBeanInstance(prototypeInstance, name, beanName, mbd);
109                 }
110 
111                 else {
112                     String scopeName = mbd.getScope();
113                     final Scope scope = this.scopes.get(scopeName);
114                     if (scope == null) {
115                         throw new IllegalStateException("No Scope registered for scope name '" + scopeName + "'");
116                     }
117                     try {
118                         Object scopedInstance = scope.get(beanName, new ObjectFactory<Object>() {
119                             @Override
120                             public Object getObject() throws BeansException {
121                                 beforePrototypeCreation(beanName);
122                                 try {
123                                     return createBean(beanName, mbd, args);
124                                 }
125                                 finally {
126                                     afterPrototypeCreation(beanName);
127                                 }
128                             }
129                         });
130                         bean = getObjectForBeanInstance(scopedInstance, name, beanName, mbd);
131                     }
132                     catch (IllegalStateException ex) {
133                         throw new BeanCreationException(beanName,
134                                 "Scope '" + scopeName + "' is not active for the current thread; consider " +
135                                 "defining a scoped proxy for this bean if you intend to refer to it from a singleton",
136                                 ex);
137                     }
138                 }
139             }
140             catch (BeansException ex) {
141                 cleanupAfterBeanCreationFailure(beanName);
142                 throw ex;
143             }
144         }
145 
146         // Check if required type matches the type of the actual bean instance.
147         if (requiredType != null && bean != null && !requiredType.isInstance(bean)) {
148             try {
149                 return getTypeConverter().convertIfNecessary(bean, requiredType);
150             }
151             catch (TypeMismatchException ex) {
152                 if (logger.isDebugEnabled()) {
153                     logger.debug("Failed to convert bean '" + name + "' to required type '" +
154                             ClassUtils.getQualifiedName(requiredType) + "'", ex);
155                 }
156                 throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
157             }
158         }
159         return (T) bean;
160     }
AbstractBeanFactory.doGetBean

17:獲取後置處理器的名稱(這裡也就是internalAutoProxyCreator)

21:根據bean名字獲取對應單例

22~33:如果獲取到的bean不為空,進行一系列操作(這裡的internalAutoProxyCreator是第一次獲取,bean應該是空,所以我們跳過22~33)

61:getMergedLocalBeanDefinition() 根據傳入的後置處理器名稱,獲取其所有信息,在這裡也就是從internalAutoProxyCreator的BeanDefinition中獲取必要信息,這是為創建bean做準備。

79:判斷如果是單例,調用getSingleton()來獲取

這裡我們先不急著進入getSingleton()方法,接著往下看先。

130:bean = getObjectForBeanInstance(scopedInstance, name, beanName, mbd)  將79行獲取的scopedInstance包裝為bean

159:返回bean

ok,getSingleton()的獲取是要返回的,所以這步是關鍵,接下來我們來看看getSingleton()。

 一直往上走,最終我們來到doCreateBean(),說明獲取不到,接下來需要創建bean了


 

 

二點三、doCreateBean()

  1 /**
  2      * Actually create the specified bean. Pre-creation processing has already happened
  3      * at this point, e.g. checking {@code postProcessBeforeInstantiation} callbacks.
  4      * <p>Differentiates between default bean instantiation, use of a
  5      * factory method, and autowiring a constructor.
  6      * @param beanName the name of the bean
  7      * @param mbd the merged bean definition for the bean
  8      * @param args explicit arguments to use for constructor or factory method invocation
  9      * @return a new instance of the bean
 10      * @throws BeanCreationException if the bean could not be created
 11      * @see #instantiateBean
 12      * @see #instantiateUsingFactoryMethod
 13      * @see #autowireConstructor
 14      */
 15     protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final Object[] args)
 16             throws BeanCreationException {
 17 
 18         // Instantiate the bean.
 19         BeanWrapper instanceWrapper = null;
 20         if (mbd.isSingleton()) {
 21             instanceWrapper = this.factoryBeanInstanceCache.remove(beanName);
 22         }
 23         if (instanceWrapper == null) {
 24             instanceWrapper = createBeanInstance(beanName, mbd, args);
 25         }
 26         final Object bean = (instanceWrapper != null ? instanceWrapper.getWrappedInstance() : null);
 27         Class<?> beanType = (instanceWrapper != null ? instanceWrapper.getWrappedClass() : null);
 28         mbd.resolvedTargetType = beanType;
 29 
 30         // Allow post-processors to modify the merged bean definition.
 31         synchronized (mbd.postProcessingLock) {
 32             if (!mbd.postProcessed) {
 33                 try {
 34                     applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);
 35                 }
 36                 catch (Throwable ex) {
 37                     throw new BeanCreationException(mbd.getResourceDescription(), beanName,
 38                             "Post-processing of merged bean definition failed", ex);
 39                 }
 40                 mbd.postProcessed = true;
 41             }
 42         }
 43 
 44         // Eagerly cache singletons to be able to resolve circular references
 45         // even when triggered by lifecycle interfaces like BeanFactoryAware.
 46         boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&
 47                 isSingletonCurrentlyInCreation(beanName));
 48         if (earlySingletonExposure) {
 49             if (logger.isDebugEnabled()) {
 50                 logger.debug("Eagerly caching bean '" + beanName +
 51                         "' to allow for resolving potential circular references");
 52             }
 53             addSingletonFactory(beanName, new ObjectFactory<Object>() {
 54                 @Override
 55                 public Object getObject() throws BeansException {
 56                     return getEarlyBeanReference(beanName, mbd, bean);
 57                 }
 58             });
 59         }
 60 
 61         // Initialize the bean instance.
 62         Object exposedObject = bean;
 63         try {
 64             populateBean(beanName, mbd, instanceWrapper);
 65             if (exposedObject != null) {
 66                 exposedObject = initializeBean(beanName, exposedObject, mbd);
 67             }
 68         }
 69         catch (Throwable ex) {
 70             if (ex instanceof BeanCreationException && beanName.equals(((BeanCreationException) ex).getBeanName())) {
 71                 throw (BeanCreationException) ex;
 72             }
 73             else {
 74                 throw new BeanCreationException(
 75                         mbd.getResourceDescription(), beanName, "Initialization of bean failed", ex);
 76             }
 77         }
 78 
 79         if (earlySingletonExposure) {
 80             Object earlySingletonReference = getSingleton(beanName, false);
 81             if (earlySingletonReference != null) {
 82                 if (exposedObject == bean) {
 83                     exposedObject = earlySingletonReference;
 84                 }
 85                 else if (!this.allowRawInjectionDespiteWrapping && hasDependentBean(beanName)) {
 86                     String[] dependentBeans = getDependentBeans(beanName);
 87                     Set<String> actualDependentBeans = new LinkedHashSet<String>(dependentBeans.length);
 88                     for (String dependentBean : dependentBeans) {
 89                         if (!removeSingletonIfCreatedForTypeCheckOnly(dependentBean)) {
 90                             actualDependentBeans.add(dependentBean);
 91                         }
 92                     }
 93                     if (!actualDependentBeans.isEmpty()) {
 94                         throw new BeanCurrentlyInCreationException(beanName,
 95                                 "Bean with name '" + beanName + "' has been injected into other beans [" +
 96                                 StringUtils.collectionToCommaDelimitedString(actualDependentBeans) +
 97                                 "] in its raw version as part of a circular reference, but has eventually been " +
 98                                 "wrapped. This means that said other beans do not use the final version of the " +
 99                                 "bean. This is often the result of over-eager type matching - consider using " +
100                                 "'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.");
101                     }
102                 }
103             }
104         }
105 
106         // Register bean as disposable.
107         try {
108             registerDisposableBeanIfNecessary(beanName, bean, mbd);
109         }
110         catch (BeanDefinitionValidationException ex) {
111             throw new BeanCreationException(
112                     mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex);
113         }
114 
115         return exposedObject;
116     }
AbstractAutowireCapableBeanFactory.doCreateBean

26:創建bean

64:populateBean(beanName, mbd, instanceWrapper) 給bean的屬性賦值

66:initializeBean(beanName, exposedObject, mbd)初始化bean

下麵我們來看這個初始化bean都做了什麼


 

 

二點四、initializeBean()

 1 /**
 2      * Initialize the given bean instance, applying factory callbacks
 3      * as well as init methods and bean post processors.
 4      * <p>Called from {@link #createBean} for traditionally defined beans,
 5      * and from {@link #initializeBean} for existing bean instances.
 6      * @param beanName the bean name in the factory (for debugging purposes)
 7      * @param bean the new bean instance we may need to initialize
 8      * @param mbd the bean definition that the bean was created with
 9      * (can also be {@code null}, if given an existing bean instance)
10      * @return the initialized bean instance (potentially wrapped)
11      * @see BeanNameAware
12      * @see BeanClassLoaderAware
13      * @see BeanFactoryAware
14      * @see #applyBeanPostProcessorsBeforeInitialization
15      * @see #invokeInitMethods
16      * @see #applyBeanPostProcessorsAfterInitialization
17      */
18     protected Object initializeBean(final String beanName, final Object bean, RootBeanDefinition mbd) {
19         if (System.getSecurityManager() != null) {

              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • "參考文章鏈接" 我的環境 conda 4.7.10、python 3.6.7、Django 3.0.3 安裝uWSGI 這裡如果出現了問題,可以考慮如下解決辦法: "參考鏈接" 最後重新運行安裝命令 測試uWSGI是否正常工作 新建一個test.py文件: 若之後要刪除則運行 輸入如下內容: 運行 ...
  • Tornado 是 FriendFeed 使用的可擴展的非阻塞式 web 伺服器及其相關工具的開源版本。這個 Web 框架看起來有些像web.py 或者 Google 的 webapp,不過為了能有效利用非阻塞式伺服器環境,這個 Web 框架還包含了一些相關的有用工具 和優化。 Tornado 和現 ...
  • 在實際的開發過程中,我們需要前端頁面向Java端提交請求,這些請求一般分為get方式和post方式,不管是哪一種方式,一般都會攜帶一些參數。這一節,我們來演示一下如何給Controller傳遞參數。 代碼: @RestController public class HelloController { ...
  • 引入模塊 1. /`a.sum(axis=None)` 根據給定軸 計算數組 相關元素之和, 整數或元組,不指定軸則預設求全部元素之和。 若 的`shape (d0,d1,..,dn) axis=(m1,m2,...mi) shape (d0,d1,...,dn) (dm1,dm2,...dmi) ...
  • 這節課,我們來學習一下SpringBoot的環境配置,在SpringBoot中,所有的配置都寫在application.properties中: 我們啟動項目,預設埠是8080,我們現在給他配置一個8088: server.port=8088 運行啟動類,然後在瀏覽器地址欄訪問上一節中的控制器: ...
  • 在開始之前,我們需要去創建一個SpringBoot項目,大家可以去 http://start.spring.io/ 這個網站生成一個項目。 如圖,這邊可以對SpringBoot項目進行詳細設置: 下麵這個web一定要勾選: SpringBoot版本號選擇1.5.10 全部設置好了以後,就點擊這個按鈕 ...
  • 1.引子 大家好,在接下里的半個多小時,我會給大家詳細的介紹SpringBoot的基本使用,相信學完這門課程以後,你會對SpringBoot有一個清晰的認識,並且能夠運用這門比較新穎的技術開發一些小程式。我也希望,這門課程能夠對大家入門SpringBoot框架起到一個良好的助推作用。 在開始之前,我 ...
  • 最近做項目測試的發現,訪問Url返回的時間與資料庫中的不相同,環境是Spring boot+MyBatis+Mysql(阿裡雲伺服器),經過一番折騰,得到瞭解決 問題描述 我是直接使用IDEA的資料庫控制台,往資料庫中某個表插入了數據,該表存在著一個欄位date,此欄位是插入數據的時候由資料庫自動賦 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...