最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot初始化加載配置的八種方式總結(jié)

 更新時(shí)間:2024年12月06日 10:38:22   作者:獨(dú)行客-編碼愛好者  
在日常開發(fā)時(shí),我們常常需要 在SpringBoot應(yīng)用啟動時(shí)執(zhí)行某一段邏輯,如獲取一些當(dāng)前環(huán)境的配置或變量、向數(shù)據(jù)庫寫入一些初始數(shù)據(jù)或者連接某些第三方系統(tǒng),確認(rèn)對方可以工作,那么在實(shí)現(xiàn)初始化邏輯代碼時(shí)就需要小心了,所以本文介紹了SpringBoot初始化加載配置的方式
  • @PostConstruct 注解
  • InitializingBean 接口
  • @Bean initMethod方法
  • 構(gòu)造器注入
  • ApplicationListener
  • CommandLineRunner
  • ApplicationRunner
  • SmartLifecycle 

序號

初始化加載方式

執(zhí)行時(shí)機(jī)

1

@PostConstruct 注解(在方法加注解)

Bean對象初始化完成后執(zhí)行( 該方法會在所有依賴字段注入后才執(zhí)行 

2

構(gòu)造器注入(構(gòu)造方法加  @Autowired注解 

Bean對象初始化完成后執(zhí)行( 該方法會在所有依賴字段注入后才執(zhí)行 

3

InitializingBean 接口(繼承 InitializingBean接口,并實(shí)現(xiàn) afterPropertiesSet()這個(gè)方法)

Bean對象初始化完成后執(zhí)行( 該方法會在所有依賴字段注入后才執(zhí)行 ) 3和4是一樣的,實(shí)現(xiàn)方式不同

4

@Bean initMethod方法

Bean對象初始化完成后執(zhí)行( 該方法會在所有依賴字段注入后才執(zhí)行  3和4是一樣的,實(shí)現(xiàn)方式不同

5

SmartLifecycle 接口(繼承SmartLifecycle 接口),并實(shí)現(xiàn)start() 方法

SmartLifecycle 的執(zhí)行時(shí)機(jī)是在 Spring 應(yīng)用上下文刷新完成之后,即所有的 Bean 都已經(jīng)被實(shí)例化和初始化之后。

6

ApplicationListener(繼承  ApplicationListener接口,并實(shí)現(xiàn)onApplicationEvent()方法  與方法上加 @EventListener的效果一樣 

所有Bean初始化完成后才會執(zhí)行方法

7

CommandLineRunner 繼承 CommandLineRunner,繼承 run() 方法 

應(yīng)用啟動后執(zhí)行

8

ApplicationRunner( 繼承 CommandLineRunner,繼承 run() 方法 

應(yīng)用啟動后執(zhí)行

背景

在日常開發(fā)時(shí),我們常常需要 在SpringBoot 應(yīng)用啟動時(shí)執(zhí)行某一段邏輯,如下面的場景:

  • 獲取一些當(dāng)前環(huán)境的配置或變量

  • 向緩存數(shù)據(jù)庫寫入一些初始數(shù)據(jù)

  • 連接某些第三方系統(tǒng),確認(rèn)對方可以工作

在實(shí)現(xiàn)這些功能時(shí),我們可能會遇到一些"坑"。 為了利用SpringBoot框架的便利性,我們不得不將整個(gè)應(yīng)用的執(zhí)行控制權(quán)交給容器,于是造成了大家對于細(xì)節(jié)是一無所知的。那么在實(shí)現(xiàn)初始化邏輯代碼時(shí)就需要小心了,比如,我們并不能簡單的將初始化邏輯在Bean類的構(gòu)造方法中實(shí)現(xiàn),類似下面的代碼:

@Component 
public class InvalidInitExampleBean { 
    @Autowired 
     private Environment env; 
    
    public InvalidInitExampleBean() { 
    
        env.getActiveProfiles(); 
    } 
}

注意:這里,我們在InvalidInitExampleBean的構(gòu)造方法中試圖訪問一個(gè)自動注入的env字段,當(dāng)真正執(zhí)行時(shí),你一定會得到一個(gè)空指針異常(NullPointerException)。原因在于,當(dāng)構(gòu)造方法被調(diào)用時(shí),Spring上下文中的Environment這個(gè)Bean很可能還沒有被實(shí)例化,同時(shí)也仍未注入到當(dāng)前對象,所以并不能這樣進(jìn)行調(diào)用。

下面,我們來看看在SpringBoot中實(shí)現(xiàn)"安全初始化"的一些方法:

一、@PostConstruct 注解

@PostConstruct 注解其實(shí)是來自于 javax的擴(kuò)展包中(大多數(shù)人的印象中是來自于Spring框架),它的作用在于聲明一個(gè)Bean對象初始化完成后執(zhí)行的方法。

來看看它的原始定義:

The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization.

也就是說,該方法會在所有依賴字段注入后才執(zhí)行,當(dāng)然這一動作也是由Spring框架執(zhí)行的。 

示例:

package com.cfcc.teis.load;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Arrays;
 
/**
 * @Description TODO
 * @date 2024/12/5 11:19
 * @Version 1.0
 * @Author gezongyang
 */
@Component
@Slf4j
public class InvalidInitExampleBean {
 
    @Autowired
    private Environment environment;
 
    /**
     * 該方法會在所有依賴字段(environment)注入后才執(zhí)行,當(dāng)然這一動作也是由Spring框架執(zhí)行的。
     */
    @PostConstruct
    public void init() {
        //environment 已經(jīng)注入
        log.info("@PostConstruct execute:{}",Arrays.asList(environment.getDefaultProfiles()));
    }
}

二、實(shí)現(xiàn) InitializingBean 接口

InitializingBean 是由Spring框架提供的接口,其與@PostConstruct注解的工作原理非常類似。

如果不使用注解的話,你需要讓Bean實(shí)例繼承 InitializingBean接口,并實(shí)現(xiàn)afterPropertiesSet()這個(gè)方法。

示例:

package com.cfcc.teis.load;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.util.Arrays;
 
/**
 * @Description 繼承 InitializingBean接口,并實(shí)現(xiàn)afterPropertiesSet()
 *  afterPropertiesSet() 會在所有依賴的字段(environment)注入后才執(zhí)行
 * @date 2024/12/5 11:37
 * @Version 1.0
 * @Author gezongyang
 */
@Component
@Slf4j
public class InitializingBeanExampleBean implements InitializingBean {
 
    @Autowired
    private Environment environment;
 
    /**
      * 這個(gè)方法會在environment注入后執(zhí)行
     */
    @Override
    public void afterPropertiesSet() {
        //environment 已經(jīng)注入
        log.info("InitializingBean execute:{}", Arrays.asList(environment.getDefaultProfiles()));
    }
}

三、@Bean initMethod方法

我們在聲明一個(gè)Bean的時(shí)候,可以同時(shí)指定一個(gè)initMethod屬性,該屬性會指向Bean的一個(gè)方法,表示在初始化后執(zhí)行。

示例:

package com.cfcc.teis.load;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.util.Arrays;
 
/**
 * @Description 指定一個(gè)initMethod屬性,該屬性會指向Bean的一個(gè)方法,表示在初始化后執(zhí)行。
 * @date 2024/12/5 11:37
 * @Version 1.0
 * @Author gezongyang
 */
@Component
@Slf4j
public class InitializingBean {
 
    @Autowired
    private Environment environment;
 
    /**
     * 這個(gè)方法會在environment注入后執(zhí)行
     */
    public void init() {
        //environment 已經(jīng)注入
        log.info("@Bean initMethod execute:{}", Arrays.asList(environment.getDefaultProfiles()));
    }
 
    /**
     * 這里將initMethod指向init方法,相應(yīng)的我們也需要在Bean中實(shí)現(xiàn)這個(gè)方法:
     * @return
     */
    @Bean(initMethod="init")
    public InitializingBean exBean() {
        return new InitializingBean();
    }
}

四、構(gòu)造器注入

如果依賴的字段在Bean的構(gòu)造方法中聲明,那么Spring框架會先實(shí)例這些字段對應(yīng)的Bean,再調(diào)用當(dāng)前的構(gòu)造方法。

package com.cfcc.teis.load;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.util.Arrays;
 
/**
 * @Description 如果依賴的字段在Bean的構(gòu)造方法中聲明,那么Spring框架會先實(shí)例這些字段對應(yīng)的Bean,
 * 再調(diào)用當(dāng)前的構(gòu)造方法。
 * @date 2024/12/5 14:11
 * @Version 1.0
 * @Author gezongyang
 */
@Slf4j
@Component
public class LogicInConstructorExampleBean {
    private final Environment environment;
 
    /**
     * LogicInConstructorExampleBean(Environment environment) 調(diào)用在
     * Environment 對象實(shí)例化之后
     * @param environment
     */
    @Autowired
    public LogicInConstructorExampleBean(Environment environment) {
        //environment實(shí)例已初始化
        this.environment = environment;
        log.info("LogicInConstructor:{}", Arrays.asList(environment.getDefaultProfiles()));
    }
}

五、實(shí)現(xiàn)ApplicationListener 接口

ApplicationListener 是由 spring-context組件提供的一個(gè)接口,主要是用來監(jiān)聽 “容器上下文的生命周期事件”。它的定義如下:

public interface ApplicationListener<E extends ApplicationEvent> extends EventListener {
    /**
     * Handle an application event.
     * @param event the event to respond to
     */
    void onApplicationEvent(E event);
}

這里的event可以是任何一個(gè)繼承于ApplicationEvent的事件對象。 對于初始化工作來說,我們可以通過監(jiān)聽ContextRefreshedEvent這個(gè)事件來捕捉上下文初始化的時(shí)機(jī)。

示例:

package com.cfcc.teis.load;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
/**
 * @Description 當(dāng)所有的Bean都初始化完成后,執(zhí)行onApplicationEvent 方法
 * @date 2024/12/5 14:19
 * @Version 1.0
 * @Author gezongyang
 */
@Slf4j
@Component
public class StartupApplicationListenerExample  implements ApplicationListener<ContextRefreshedEvent> {
    public static int counter;
 
    /**
     * 這里的event可以是任何一個(gè)繼承于ApplicationEvent的事件對象。
     * 對于初始化工作來說,我們可以通過監(jiān)聽ContextRefreshedEvent這個(gè)事件來捕捉上下文初始化的時(shí)機(jī)。
     * @param event
     */
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        log.info("ApplicationListener run!");
        counter++;
    }
}

在Spring上下文初始化完成后,這里定義的方法將會被執(zhí)行。 與前面的 InitializingBean 不同的是,通過 ApplicationListener 監(jiān)聽的方式是全局性的,也就是當(dāng) 所有 的 Bean 都 初始化完成 后才會執(zhí)行方法。
Spring 4.2 之后引入了新的 @EventListener注解,可以實(shí)現(xiàn)同樣的效果:

package com.cfcc.teis.load;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
 
/**
 * @Description TODO
 * @date 2024/12/5 14:24
 * @Version 1.0
 * @Author gezongyang
 */
@Slf4j
@Component
public class EventListenerExampleBean {
    public static int counter;
 
    /**
     * 所有的Bean都初始化完成后,執(zhí)行onApplicationEvent方法。
     * @param event
     */
    @EventListener
    public void onApplicationEvent(ContextRefreshedEvent event) {
        log.info("@EventListener execute", event.toString());
        counter++;
    }
}

六、實(shí)現(xiàn) CommandLineRunner 接口

SpringBoot 提供了一個(gè)CommanLineRunner接口,用來實(shí)現(xiàn)在應(yīng)用啟動后的邏輯控制,其定義如下:

public interface CommandLineRunner {
    /**
     * Callback used to run the bean.
     * @param args incoming main method arguments
     * @throws Exception on error
     */
    void run(String... args) throws Exception;
}

此外,對于多個(gè)CommandLineRunner的情況下可以使用@Order注解來控制它們的順序。

案例:

1 定義一個(gè)CommandDemo實(shí)現(xiàn)CommandLineRunner,并納入到spring容器

package com.cfcc.teis.load;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
/**
 * @Description 應(yīng)用啟動后的回調(diào)函數(shù),在應(yīng)用啟動后執(zhí)行此方法
 * @date 2024/12/5 14:32
 * @Version 1.0
 * @Author gezongyang
 */
@Component
@Slf4j
public class CommandDemo implements CommandLineRunner {
    /**
     * 此方法在應(yīng)用啟動后執(zhí)行
     * @param args
     */
    @Override
    public void run(String... args) {
        log.info("CommandLineRunner run!");
    }
}

2 配置參數(shù),然后執(zhí)行啟動類

3 打印結(jié)果:

=====應(yīng)用已經(jīng)啟動成功======[aaa,bbb]

七、實(shí)現(xiàn) ApplicationRunner 接口

package org.springframework.boot;
 
 
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
 
 
/**
* Interface used to indicate that a bean should <em>run</em> when it is contained within
* a {@link SpringApplication}. Multiple {@link ApplicationRunner} beans can be defined
* within the same application context and can be ordered using the {@link Ordered}
* interface or {@link Order @Order} annotation.
*
* @author Phillip Webb
* @since 1.3.0
* @see CommandLineRunner
*/
@FunctionalInterface
public interface ApplicationRunner {
 
   /**
    * Callback used to run the bean.
    * @param args incoming application arguments
    * @throws Exception on error
    */
   void run(ApplicationArguments args) throws Exception;
}

與 CommandLineRunner接口類似, Spring boot 還提供另一個(gè)ApplicationRunner 接口來實(shí)現(xiàn)初始化邏輯。不同的地方在于 ApplicationRunner.run()方法接受的是封裝好的ApplicationArguments參數(shù)對象,而不是簡單的字符串參數(shù)。ApplicationArguments是對參數(shù)做了進(jìn)一步的處理,可以解析key=value形式,我們可以通過name來獲取value(而CommandLineRunner只是獲取key=value整體)

package org.springframework.boot;
 
import java.util.List;
import java.util.Set;
/**
* Provides access to the arguments that were used to run a {@link SpringApplication}.
*
* @author Phillip Webb
* @since 1.3.0
*/
public interface ApplicationArguments {
 
   /**
    * Return the raw unprocessed arguments that were passed to the application.
    * @return the arguments
    */
   String[] getSourceArgs();
 
   /**
    * Return the names of all option arguments. For example, if the arguments were
    * "--foo=bar --debug" would return the values {@code ["foo", "debug"]}.
    * @return the option names or an empty set
    */
   Set<String> getOptionNames();
 
   /**
    * Return whether the set of option arguments parsed from the arguments contains an
    * option with the given name.
    * @param name the name to check
    * @return {@code true} if the arguments contain an option with the given name
    */
   boolean containsOption(String name);
 
   /**
    * Return the collection of values associated with the arguments option having the
    * given name.
    * <ul>
    * <li>if the option is present and has no argument (e.g.: "--foo"), return an empty
    * collection ({@code []})</li>
    * <li>if the option is present and has a single value (e.g. "--foo=bar"), return a
    * collection having one element ({@code ["bar"]})</li>
    * <li>if the option is present and has multiple values (e.g. "--foo=bar --foo=baz"),
    * return a collection having elements for each value ({@code ["bar", "baz"]})</li>
    * <li>if the option is not present, return {@code null}</li>
    * </ul>
    * @param name the name of the option
    * @return a list of option values for the given name
    */
   List<String> getOptionValues(String name);
 
   /**
    * Return the collection of non-option arguments parsed.
    * @return the non-option arguments or an empty list
    */
   List<String> getNonOptionArgs();
}

ApplicationArguments可以接收key=value這樣的參數(shù),getOptionNames()方法可以得到key的集合,getOptionValues(String name)方法可以得到value這樣的集合

示例:

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
 
/**
* @Description TODO
* @date 2022/6/23 9:55
* @Version 1.0
* @Author gezongyang
*/
@Component
public class ApplicationRunnerDemo implements ApplicationRunner {
 
    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("====getOptionNames======"+args.getOptionNames());
        System.out.println("====getOptionValues====="+args.getOptionValues("key"));
    }
}

配置參數(shù)啟動

打印結(jié)果:

====getOptionNames======[key]
====getOptionValues=====[value]

八、實(shí)現(xiàn)SmartLifecycle 接口

package org.springframework.context;
 
public interface SmartLifecycle extends Lifecycle, Phased {
    boolean isAutoStartup();
    void stop(Runnable var1);
}

SmartLifecycle 是 Spring Framework 中的一個(gè)接口,它擴(kuò)展了 Lifecycle 接口,并提供了更靈活的生命周期管理功能。使用 SmartLifecycle 可以更精細(xì)地控制應(yīng)用組件的啟動和關(guān)閉過程。以下是 SmartLifecycle 的一些主要特性:

特性:

isAutoStartup(): 返回一個(gè)布爾值,指示該組件是否應(yīng)該在容器啟動時(shí)自動啟動。

getPhase(): 返回一個(gè)整數(shù)值,表示組件的啟動順序(階段)。較低的數(shù)字表示較早的啟動順序。

start(): 啟動組件,當(dāng)返回時(shí),組件應(yīng)該已經(jīng)啟動完畢。

stop(Runnable callback): 停止組件,并且可以在停止完成后執(zhí)行提供的回調(diào)函數(shù)。

isRunning(): 返回一個(gè)布爾值,指示組件當(dāng)前是否處于運(yùn)行狀態(tài)。

案例:

package com.cfcc.teis.load;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.SmartLifecycle;
import org.springframework.stereotype.Component;
 
/**
 * @Description SmartLifecycle 可以更精細(xì)地控制應(yīng)用組件的啟動和關(guān)閉過程
 * @date 2024/12/5 15:10
 * @Version 1.0
 * @Author gezongyang
 */
@Slf4j
@Component
public class SmartLifecycleDemo implements SmartLifecycle {
 
    private volatile boolean running = false;
 
    /**
     * SmartLifecycle run
     */
    @Override
    public void start() {
        log.info("SmartLifecycle run!");
        this.running = true;
    }
 
    @Override
    public void stop() {
 
    }
 
    /**
     * 在這里放置停止邏輯
     * @param callback
     */
    @Override
    public void stop(Runnable callback) {
        this.running = false;
        callback.run();  // 確?;卣{(diào)被執(zhí)行
    }
 
    @Override
    public boolean isRunning() {
        return this.running;
    }
 
    /**
     * 組件將在Spring上下文加載后自動啟動
     * @return
     */
    @Override
    public boolean isAutoStartup() {
        return true;
    }
 
    /**
     * 定義啟動順序,數(shù)字越小越先啟動
     * @return
     */
    @Override
    public int getPhase() {
        return 0;
    }
}

注意事項(xiàng)

當(dāng)你實(shí)現(xiàn) SmartLifecycle 時(shí),確保 start() 方法不會阻塞,因?yàn)樗鼤舆t整個(gè)應(yīng)用程序的啟動。如果需要長時(shí)間運(yùn)行的任務(wù),考慮將其放入單獨(dú)的線程中。

stop(Runnable callback) 方法中的回調(diào)是重要的,必須調(diào)用它來通知框架組件已經(jīng)停止。如果你不打算使用某些方法,可以不重寫它們;默認(rèn)實(shí)現(xiàn)將提供合理的行為。

通過使用 SmartLifecycle,你可以更好地控制應(yīng)用程序中不同組件的生命周期行為,這對于那些對啟動和關(guān)閉有特殊需求的應(yīng)用特別有用。

SmartLifecycle 的執(zhí)行時(shí)機(jī):

是在 Spring 應(yīng)用上下文刷新完成之后,即所有的 Bean 都已經(jīng)被實(shí)例化和初始化之后。具體來說,Spring 容器在調(diào)用 finishRefresh() 方法時(shí)會觸發(fā)所有實(shí)現(xiàn)了 SmartLifecycle 接口的 Bean 的啟動過程。這是通過容器中的 LifecycleProcessor 來管理的,默認(rèn)使用的是 DefaultLifecycleProcessor。

SmartLifecycle 執(zhí)行的具體流程

上下文刷新完成后:當(dāng) Spring 應(yīng)用上下文完成刷新(finishRefresh),意味著所有的 Bean 已經(jīng)被加載并初始化完畢。

初始化生命周期處理器:Spring 會初始化 LifecycleProcessor,如果沒有顯式定義,則創(chuàng)建一個(gè)默認(rèn)的 DefaultLifecycleProcessor。

調(diào)用 onRefresh():接著,Spring 會調(diào)用 LifecycleProcessor 的 onRefresh() 方法,這將導(dǎo)致調(diào)用 startBeans() 方法。

根據(jù) phase 分組并排序:startBeans() 方法會獲取所有實(shí)現(xiàn)了 Lifecycle 接口的 Bean,并根據(jù)它們的 phase 屬性進(jìn)行分組和排序。phase 值越小的 Bean 將越早啟動。

檢查 isAutoStartup():對于每個(gè) SmartLifecycle Bean,如果它的 isAutoStartup() 方法返回 true,那么它的 start() 方法就會被自動調(diào)用。

執(zhí)行 start() 方法:按照 phase 排序后的順序,依次調(diào)用每個(gè) SmartLifecycle Bean 的 start() 方法來啟動組件。

設(shè)置運(yùn)行狀態(tài):start() 方法應(yīng)該確保組件處于運(yùn)行狀態(tài),并且 isRunning() 方法應(yīng)返回 true。

同樣的邏輯也適用于停止組件的過程,但是是以相反的順序執(zhí)行的,即 phase 值較大的 Bean 會先停止。

因此,如果你希望在 Spring 容器完全準(zhǔn)備好之后執(zhí)行某些任務(wù),比如開啟消息監(jiān)聽、啟動定時(shí)任務(wù)等,你可以實(shí)現(xiàn) SmartLifecycle 接口并在 start() 方法中放置這些邏輯。同時(shí),通過調(diào)整 getPhase() 返回的值,可以控制多個(gè) SmartLifecycle Bean 之間的啟動順序。

以上就是SpringBoot初始化加載配置的八種方式總結(jié)的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot初始化加載配置的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • SpringBoot靜態(tài)資源路徑配置及主頁顯示

    SpringBoot靜態(tài)資源路徑配置及主頁顯示

    這篇文章主要介紹了SpringBoot靜態(tài)資源路徑配置及主頁顯示,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • PowerJob的QueryConvertUtils工作流程源碼解讀

    PowerJob的QueryConvertUtils工作流程源碼解讀

    這篇文章主要為大家介紹了PowerJob的QueryConvertUtils工作流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • 淺析Java中的內(nèi)存泄漏

    淺析Java中的內(nèi)存泄漏

    這篇文章主要介紹了Java中的內(nèi)存泄漏,包括其基本概念和基本的預(yù)防措施,需要的朋友可以參考下
    2015-07-07
  • 簡單工廠模式_動力節(jié)點(diǎn)Java學(xué)院整理

    簡單工廠模式_動力節(jié)點(diǎn)Java學(xué)院整理

    這篇文章主要介紹了簡單工廠模式的相關(guān)資料,和大家一起學(xué)習(xí)靜態(tài)工廠方法模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Kotlin 單例實(shí)例詳解

    Kotlin 單例實(shí)例詳解

    這篇文章主要介紹了Kotlin 單例實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • Java實(shí)現(xiàn)畫線、矩形、橢圓、字符串功能

    Java實(shí)現(xiàn)畫線、矩形、橢圓、字符串功能

    本篇文章主要介紹了Java實(shí)現(xiàn)畫線、矩形、橢圓、字符串功能的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-05-05
  • JSON反序列化中的字段命名沖突問題的解決方案解析

    JSON反序列化中的字段命名沖突問題的解決方案解析

    在現(xiàn)代Java開發(fā)中,JSON已成為前后端交互、微服務(wù)通信和數(shù)據(jù)存儲的標(biāo)準(zhǔn)格式之一,本文將通過一個(gè)真實(shí)的錯(cuò)誤案例,詳細(xì)分析SerializationException的產(chǎn)生原因,并提供多種解決方案
    2025-08-08
  • SpringBoot如何集成Token

    SpringBoot如何集成Token

    文章介紹了如何使用jjwt插件實(shí)現(xiàn)Token的生成和校驗(yàn),該插件可以直接與SpringBoot集成,Token由三部分組成,分別是header、payload和signature,通過在請求頭中傳遞Token,后端可以驗(yàn)證其合法性,從而提高安全性
    2025-01-01
  • 解決Eclipse打開.java文件異常,提示用系統(tǒng)工具打開的問題

    解決Eclipse打開.java文件異常,提示用系統(tǒng)工具打開的問題

    這篇文章主要介紹了解決Eclipse打開.java文件異常,提示用系統(tǒng)工具打開的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • java實(shí)現(xiàn)在SSM下使用支付寶掃碼支付功能

    java實(shí)現(xiàn)在SSM下使用支付寶掃碼支付功能

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)在SSM下使用支付寶掃碼支付功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-02-02

最新評論

如东县| 安庆市| 临高县| 绥化市| 黑龙江省| 惠安县| 南皮县| 岐山县| 荆州市| 大名县| 营山县| 方正县| 绥宁县| 高雄市| 伊吾县| 营山县| 连南| 平凉市| 云南省| 屯门区| 正安县| 大庆市| 东平县| 浦东新区| 高州市| 中西区| 宁阳县| 定结县| 麻阳| 吴桥县| 邢台县| 牙克石市| 启东市| 会昌县| 舞阳县| 象州县| 绵阳市| 桂阳县| 荆门市| 郎溪县| 保德县|