@PostConstruct使用說明__PostConstruct

來源:互聯網
上載者:User

javax.annotation.PostConstruct的使用說明


以下是原文翻譯,注釋已經說明得很清楚了


The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. 
PostConstruct註解使用在方法上,這個方法需要在依賴注入初始化之後執行。


This method MUST be invoked before the class is put into service. 
這個方法必須在該服務類使用之前執行。


This annotation MUST be supported on all classes that support dependency injection.
支援依賴注入的所有類都必須支援該註解。


The method annotated with PostConstruct MUST be invoked even if the class does not request any resources to be injected.
該方法必須執行,即使所在的類沒有注入任何資源。


Only one method can be annotated with this annotation.
只能有一個方法使用該註解。


The method on which the PostConstruct annotation is applied MUST fulfill all of the following criteria - - 
使用了該註解的方法必須全部符合以下準則:


The method MUST NOT have any parameters except in the case of EJB interceptors in which case it takes an Invocation Context object as defined by the EJB specification. 
除EJB介面外不能擁有任何參數,


- The return type of the method MUST be void.
傳回值必須是void


 - The method MUST NOT throw a checked exception. 
該方法不能拋出異常


- The method on which PostConstruct is applied MAY be public, protected, package private or private. 
可以使用public、protected等修飾符


- The method MUST NOT be static except for the application client.
方法不是是static修飾,除非是應用程式用戶端


- The method MAY be final. 
方法可以使用final修飾


- If the method throws an unchecked exception the class MUST NOT be put into service except in the case of EJBs where the EJB can handle exceptions and even recover from them.
方法如果拋出未知異常,則類絕不能作為service類,除非是可以處理異常甚至能恢複正常的EJB組件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.