這篇“Springboot怎么在啟動前執(zhí)行代碼”文章的知識點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“Springboot怎么在啟動前執(zhí)行代碼”文章吧。
在Springboot自動實(shí)例化類前,我們需要準(zhǔn)備一些數(shù)據(jù)在類型實(shí)例化的時(shí)候使用。 經(jīng)過測試,在啟動類添加注解@PostConstruct
有效。
@SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } // springboot正式啟動前 @PostConstruct public void postConstruct(){ System.out.println("執(zhí)行Springboot正式啟動前的代碼") } }
實(shí)現(xiàn)Spring的ApplicationRunner
與CommandLineRunner
接口的辦法,都只在Springboot啟動完成后才執(zhí)行。
以上就是關(guān)于“Springboot怎么在啟動前執(zhí)行代碼”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享題目:Springboot怎么在啟動前執(zhí)行代碼-創(chuàng)新互聯(lián)
URL分享:http://chinadenli.net/article8/ddehip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、外貿(mào)建站、做網(wǎng)站、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容