欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java程序啟動時初始化數(shù)據(jù)的四種方式

 更新時間:2024年02月04日 09:49:02   作者:huixiyang  
本文主要介紹了Java程序啟動時初始化數(shù)據(jù)的四種方式,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

方式一: 利用  @PostConstruct 注解

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author yangxihui
 * @Date 2023-11-29 15:06
 * @Description
 */
@Component
public class MyInitTest {

    @PostConstruct
    public void init(){
        System.out.println("------------init");
    }
}

方式二: 實現(xiàn)類  InitializingBean

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

/**
 * @Author yangxihui
 * @Date 2023-11-29 15:06
 * @Description
 */
@Component
public class MyInitTest implements InitializingBean{

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("------------init");
    }
}

方式三: 實現(xiàn)類 CommandLineRunner

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @Author yangxihui
 * @Date 2023-11-29 15:24
 * @Description
 */
@Component
public class MyInitTest implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        System.out.println("------------init");
    }
}

方式四: springboot main方法中

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class LoginApplication {

	public static void main(String[] args) {
		SpringApplication.run(LoginApplication.class, args);
		System.out.println("------------init");
	}

}

到此這篇關(guān)于Java程序啟動時初始化數(shù)據(jù)的四種方式的文章就介紹到這了,更多相關(guān)Java 初始化數(shù)據(jù) 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • maven導(dǎo)入本地倉庫jar包,報:Could?not?find?artifact的解決

    maven導(dǎo)入本地倉庫jar包,報:Could?not?find?artifact的解決

    這篇文章主要介紹了maven導(dǎo)入本地倉庫jar包,報:Could?not?find?artifact的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • SpringBoot3整合Hutool-captcha實現(xiàn)圖形驗證碼

    SpringBoot3整合Hutool-captcha實現(xiàn)圖形驗證碼

    在整合技術(shù)框架的時候,想找一個圖形驗證碼相關(guān)的框架,看到很多驗證碼的maven庫不再更新了或中央倉庫下載不下來,還需要多引入依賴,后面看到了Hutool圖形驗證碼(Hutool-captcha)中對驗證碼的實現(xiàn),所以本文介紹了SpringBoot3整合Hutool-captcha實現(xiàn)圖形驗證碼
    2024-11-11
  • springboot+chatgpt+chatUI Pro開發(fā)智能聊天工具的實踐

    springboot+chatgpt+chatUI Pro開發(fā)智能聊天工具的實踐

    本文主要介紹了springboot+chatgpt+chatUI Pro開發(fā)智能聊天工具的實踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Netty分布式NioEventLoop優(yōu)化selector源碼解析

    Netty分布式NioEventLoop優(yōu)化selector源碼解析

    這篇文章主要介紹了Netty分布式NioEventLoop優(yōu)化selector源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-03-03
  • Java RocksDB安裝與應(yīng)用

    Java RocksDB安裝與應(yīng)用

    本篇文章主要給大家介紹了JAVA中RocksDB的安裝與應(yīng)用,有需要到的朋友一起學(xué)習(xí)參考下。
    2017-12-12
  • Java線程創(chuàng)建與Thread類的使用方法

    Java線程創(chuàng)建與Thread類的使用方法

    這篇文章主要介紹了Java線程創(chuàng)建與Thread類的使用方法,圍繞java多線程中Thread類的使用以及有關(guān)線程對象創(chuàng)建和常用方法的相關(guān)資料展開詳細(xì)內(nèi)容,具有一定的參考價值,需要的下伙伴可以參考一下
    2022-06-06
  • Java Predicate接口定義詳解

    Java Predicate接口定義詳解

    Predicate是Java中的一個函數(shù)式接口,它代表一個判斷邏輯,接收一個輸入?yún)?shù),返回一個布爾值,這篇文章主要介紹了Java Predicate接口的定義及示例代碼,需要的朋友可以參考下
    2025-04-04
  • Java @GlobalLock注解詳細(xì)分析講解

    Java @GlobalLock注解詳細(xì)分析講解

    這篇文章主要介紹了Java @GlobalLock注解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-11-11
  • Java jdbc批量多線程讀取CVS文件入庫

    Java jdbc批量多線程讀取CVS文件入庫

    這篇文章主要為大家詳細(xì)介紹了Java jdbc批量多線程讀取CVS文件入庫,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • java 線程的生命周期詳解

    java 線程的生命周期詳解

    這篇文章主要介紹了java 線程的生命周期詳解的相關(guān)資料,需要的朋友可以參考下
    2017-07-07

最新評論