亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SpringBoot自動裝配原理及過程解讀

 更新時間:2025年09月23日 09:55:52   作者:埃澤漫筆  
文章解析SpringBoot自動裝配機制,結合SPI源碼分析與手寫Starter實踐,闡述如何通過ServiceLoader和SpringFactoriesLoader實現(xiàn)服務發(fā)現(xiàn)及動態(tài)配置加載,并利用條件注解@Conditional進行智能過濾,最終指導開發(fā)者自定義Starter并配置屬性提示

一、SPI源碼分析

為什么要講SPI呢?因為在SpringBoot的自動裝配中其實有使用到SPI機制,所以掌握了這部分對于SpringBoot的學習還是很有幫助的。

SPI ,全稱為 Service Provider Interface,是一種服務發(fā)現(xiàn)機制。它通過在ClassPath路徑下的 META-INF/services 文件夾查找文件,自動加載文件里所定義的類。這一機制為很多框架擴展提供了可能,比如在Dubbo、JDBC中都使用到了SPI機制。我們先通過一個很簡單的例子來看下它是怎么用的。

案例介紹

先定義接口項目

然后創(chuàng)建一個擴展的實現(xiàn),先導入上面接口項目的依賴

<dependencies>
         <dependency>
             <groupId>com.bobo</groupId>
             <artifactId>JavaSPIBase</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
     </dependencies>

然后創(chuàng)建接口的實現(xiàn)

/**
  * SPI:MySQL對于 baseURL 的一種實現(xiàn)
  */
 public class MySQLData implements BaseData {
     @Override
     public void baseURL() {
         System.out.println("mysql 的擴展實現(xiàn)....");
     }
 }

然后在resources目錄下創(chuàng)建 META-INF/services 目錄,然后在目錄中創(chuàng)建一個文件,名稱必須是定義的接口的全類路徑名稱。然后在文件中寫上接口的實現(xiàn)類的全類路徑名稱。

同樣的再創(chuàng)建一個案例

然后在測試的項目中測試

public static void main(String[] args) {
         ServiceLoader<BaseData> providers = ServiceLoader.load(BaseData.class);
         Iterator<BaseData> iterator = providers.iterator();
         while(iterator.hasNext()){
             BaseData next = iterator.next();
             next.baseURL();
         }
     }

根據不同的導入,執(zhí)行的邏輯會有不同

源碼查看

  • ServiceLoader

首先來看下ServiceLoader的類結構

// 配置文件的路徑
     private static final String PREFIX = "META-INF/services/";
 
     // 加載的服務  類或者接口
     private final Class<S> service;
 
     // 類加載器
     private final ClassLoader loader;
 
     // 訪問權限的上下文對象
     private final AccessControlContext acc;
 
     // 保存已經加載的服務類
     private LinkedHashMap<String,S> providers = new LinkedHashMap<>();
 
     // 內部類,真正加載服務類
     private LazyIterator lookupIterator;
  • load

load方法創(chuàng)建了一些屬性,重要的是實例化了內部類,LazyIterator。

public final class ServiceLoader<S> implements Iterable<S>
     private ServiceLoader(Class<S> svc, ClassLoader cl) {
         //要加載的接口
         service = Objects.requireNonNull(svc, "Service interface cannot be null");
         //類加載器
         loader = (cl == null) ? ClassLoader.getSystemClassLoader() : cl;
         //訪問控制器
         acc = (System.getSecurityManager() != null) ? AccessController.getContext() : null;
          reload();
         
     }
     public void reload() {
         //先清空
         providers.clear();
         //實例化內部類 
         LazyIterator lookupIterator = new LazyIterator(service, loader);
     }
 }

查找實現(xiàn)類和創(chuàng)建實現(xiàn)類的過程,都在LazyIterator完成。

當我們調用iterator.hasNext和iterator.next方法的時候,實際上調用的都是LazyIterator的相應方法。

private class LazyIterator implements Iterator<S>{
     Class<S> service;
     ClassLoader loader;
     Enumeration<URL> configs = null;
     Iterator<String> pending = null;
     String nextName = null; 
     private boolean hasNextService() {
         //第二次調用的時候,已經解析完成了,直接返回
         if (nextName != null) {
             return true;
         }
         if (configs == null) {
             //META-INF/services/ 加上接口的全限定類名,就是文件服務類的文件
             //META-INF/services/com.viewscenes.netsupervisor.spi.SPIService
             String fullName = PREFIX + service.getName();
             //將文件路徑轉成URL對象
             configs = loader.getResources(fullName);
         }
         while ((pending == null) || !pending.hasNext()) {
             //解析URL文件對象,讀取內容,最后返回
             pending = parse(service, configs.nextElement());
         }
         //拿到第一個實現(xiàn)類的類名
         nextName = pending.next();
         return true;
     }
 }

創(chuàng)建實例對象,當然,調用next方法的時候,實際調用到的是,lookupIterator.nextService。

它通過反射的方式,創(chuàng)建實現(xiàn)類的實例并返回。

private class LazyIterator implements Iterator<S>{
     private S nextService() {
         //全限定類名
         String cn = nextName;
         nextName = null;
         //創(chuàng)建類的Class對象
         Class<?> c = Class.forName(cn, false, loader);
         //通過newInstance實例化
         S p = service.cast(c.newInstance());
         //放入集合,返回實例
         providers.put(cn, p);
         return p; 
     }
 }

看到這兒,我想已經很清楚了。獲取到類的實例,我們自然就可以對它為所欲為了!

二、自動裝配源碼分析

在前面的分析中,Spring Framework一直在致力于解決一個問題,就是如何讓bean的管理變得更簡單,如何讓開發(fā)者盡可能的少關注一些基礎化的bean的配置,從而實現(xiàn)自動裝配。所以,所謂的自動裝配,實際上就是如何自動將bean裝載到Ioc容器中來。

實際上在spring 3.x版本中,Enable模塊驅動注解的出現(xiàn),已經有了一定的自動裝配的雛形,而真正能夠實現(xiàn)這一機制,還是在spirng 4.x版本中,conditional條件注解的出現(xiàn)。ok,我們來看一下spring boot的自動裝配是怎么一回事。

自動裝配的演示

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
 </dependency>
spring:
    redis:
      host: 127.0.0.1 
      port: 6379
@Autowired
    private RedisTemplate<String,String>redisTemplate;

按照下面的順序添加starter,然后添加配置,使用RedisTemplate就可以使用了? 那大家想沒想過一個問題,為什么RedisTemplate可以被直接注入?它是什么時候加入到Ioc容器的呢? 這就是自動裝配。自動裝配可以使得classpath下依賴的包相關的bean,被自動裝載到Spring Ioc容器中,怎么做到的呢?

深入分析EnableAutoConfiguration

EnableAutoConfiguration的主要作用其實就是幫助springboot應用把所有符合條件的@Configuration配置都加載到當前SpringBoot創(chuàng)建并使用的IoC容器中。

再回到EnableAutoConfiguration這個注解中,我們發(fā)現(xiàn)它的import是這樣

@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {

但是從EnableAutoCOnfiguration上面的import注解來看,這里面并不是引入另外一個Configuration。而是一個ImportSelector。這個是什么東西呢?

AutoConfigurationImportSelector是什么?

Enable注解不僅僅可以像前面演示的案例一樣很簡單的實現(xiàn)多個Configuration的整合,還可以實現(xiàn)一些復雜的場景,比如可以根據上下文來激活不同類型的bean,@Import注解可以配置三種不同的class

第一種就是前面演示過的,基于普通bean或者帶有@Configuration的bean進行諸如

實現(xiàn)ImportSelector接口進行動態(tài)注入

實現(xiàn)ImportBeanDefinitionRegistrar接口進行動態(tài)注入

  • CacheService:
public class CacheService {}
  • LoggerService:
public class LoggerService {}
  • EnableDefineService:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented 
@Inherited  --允許被繼承
@Import({MyDefineImportSelector.class})
public @interface EnableDefineService {

    String[] packages() default "";
}
  • MyDefineImportSelector:
public class MyDefineImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        //獲得指定注解的詳細信息。我們可以根據注解中配置的屬性來返回不同的class,
        //從而可以達到動態(tài)開啟不同功能的目的
    
annotationMetadata.getAllAnnotationAttributes(EnableDefineService.class.getName(),true)
            .forEach((k,v) -> {
                log.info(annotationMetadata.getClassName());
                log.info("k:{},v:{}",k,String.valueOf(v));
            });
        return new String[]{CacheService.class.getName()};
    }
}
  • EnableDemoTest:
@SpringBootApplication
@EnableDefineService(name = "aizer",value = "aizer")
public class EnableDemoTest {
    public static void main(String[] args) {
        ConfigurableApplicationContext ca=SpringApplication.run(EnableDemoTest.class,args);
        System.out.println(ca.getBean(CacheService.class));
        System.out.println(ca.getBean(LoggerService.class));
    }
}

了解了selector的基本原理之后,后續(xù)再去分析AutoConfigurationImportSelector的原理就很簡單了,它本質上也是對于bean的動態(tài)加載。

@EnableAutoConfiguration注解的實現(xiàn)原理

了解了ImportSelector和ImportBeanDefinitionRegistrar后,對于EnableAutoConfiguration的理解就容易一些了

它會通過import導入第三方提供的bean的配置類:AutoConfigurationImportSelector

@Import(AutoConfigurationImportSelector.class)

從名字來看,可以猜到它是基于ImportSelector來實現(xiàn)基于動態(tài)bean的加載功能。之前我們講過Springboot @Enable*注解的工作原理ImportSelector接口selectImports返回的數組(類的全類名)都會被納入到spring容器中。

那么可以猜想到這里的實現(xiàn)原理也一定是一樣的,定位到AutoConfigurationImportSelector這個類中的selectImports方法

  • selectImports:
public String[] selectImports(AnnotationMetadata annotationMetadata) {
   if (!isEnabled(annotationMetadata)) {
      return NO_IMPORTS;
   }
// 從配置文件(spring-autoconfigure-metadata.properties)中加載 AutoConfigurationMetadata
   AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader
         .loadMetadata(this.beanClassLoader);
// 獲取所有候選配置類EnableAutoConfiguration
   AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(
         autoConfigurationMetadata, annotationMetadata);
   return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
}
  • getAutoConfigurationEntry:
protected AutoConfigurationEntry getAutoConfigurationEntry(
      AutoConfigurationMetadata autoConfigurationMetadata,
      AnnotationMetadata annotationMetadata) {
   if (!isEnabled(annotationMetadata)) {
      return EMPTY_ENTRY;
   }
//獲取元注解中的屬性
   AnnotationAttributes attributes = getAttributes(annotationMetadata);
//使用SpringFactoriesLoader 加載classpath路徑下META-INF\spring.factories中,
//key= org.springframework.boot.autoconfigure.EnableAutoConfiguration對應的value
   List<String> configurations = getCandidateConfigurations(annotationMetadata,
         attributes);
//去重
   configurations = removeDuplicates(configurations);
//應用exclusion屬性
   Set<String> exclusions = getExclusions(annotationMetadata, attributes);
   checkExcludedClasses(configurations, exclusions);
   configurations.removeAll(exclusions);
//過濾,檢查候選配置類上的注解@ConditionalOnClass,如果要求的類不存在,則這個候選類會被過濾不被加載
   configurations = filter(configurations, autoConfigurationMetadata);
   //廣播事件
fireAutoConfigurationImportEvents(configurations, exclusions);
   return new AutoConfigurationEntry(configurations, exclusions);
}

本質上來說,其實EnableAutoConfiguration會幫助springboot應用把所有符合@Configuration配置都加載到當前SpringBoot創(chuàng)建的IoC容器,而這里面借助了Spring框架提供的一個工具類SpringFactoriesLoader的支持。以及用到了Spring提供的條件注解@Conditional,選擇性的針對需要加載的bean進行條件過濾

SpringFactoriesLoader

為了給大家補一下基礎,我在這里簡單分析一下SpringFactoriesLoader這個工具類的使用。它其實和java中的SPI機制的原理是一樣的,不過它比SPI更好的點在于不會一次性加載所有的類,而是根據key進行加載。

首先,SpringFactoriesLoader的作用是從classpath/META-INF/spring.factories文件中,根據key來加載對應的類到spring IoC容器中。接下來帶大家實踐一下

  • 創(chuàng)建外部項目jar:
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>4.3.13.RELEASE</version>
</dependency>
  • 創(chuàng)建bean以及config:
public class aizerCore {
    public String study(){
        System.out.println("good good study, day day up");
        return "aizerEdu.com";
    }
}
@Configuration
public class aizerConfig {
    @Bean
    public aizerCore aizerCore(){
        return new aizerCore();
    }
}
  • 創(chuàng)建另外一個工程(spring-boot):

把前面的工程打包成jar,當前項目依賴該jar包

<dependency>
    <groupId>com.aizeredu.practice</groupId>
    <artifactId>aizer-Core</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>
  • 通過下面代碼獲取依賴包中的屬性:

運行結果會報錯,原因是aizerCore并沒有被Spring的IoC容器所加載,也就是沒有被EnableAutoConfiguration導入

@SpringBootApplication
public class SpringBootStudyApplication {
    public static void main(String[] args) throws IOException {
        ConfigurableApplicationContext ac=SpringApplication.run(SpringBootStudyApplication.class, args);
        aizerCore Myc=ac.getBean(aizerCore.class);
        System.out.println(Myc.study());
    }
}
  • 解決方案:

在aizer-Core項目resources下新建文件夾META-INF,在文件夾下面新建spring.factories文件,文件中配置,key為自定配置類EnableAutoConfiguration的全路徑,value是配置類的全路徑

org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.aizeredu.practice.aizerConfig

重新打包,重新運行SpringBootStudyApplication這個類。

可以發(fā)現(xiàn),我們編寫的那個類,就被加載進來了。

Spring Boot中的條件過濾

在分析AutoConfigurationImportSelector的源碼時,會先掃描spring-autoconfiguration-metadata.properties文件,最后在掃描spring.factories對應的類時,會結合前面的元數據進行過濾,為什么要過濾呢?

原因是很多的@Configuration其實是依托于其他的框架來加載的,如果當前的classpath環(huán)境下沒有相關聯(lián)的依賴,則意味著這些類沒必要進行加載,所以,通過這種條件過濾可以有效的減少@configuration類的數量從而降低SpringBoot的啟動時間。

修改aizer-Core:

在META-INF/增加配置文件,spring-autoconfigure-metadata.properties。

com.aizeredu.practice.aizerConfig.ConditionalOnClass=com.aizeredu.TestClass

格式:自動配置的類全名.條件=值

上面這段代碼的意思就是,如果當前的classpath下存在TestClass,則會對aizerConfig這個Configuration進行加載

演示過程(spring-boot):

沿用前面spring-boot工程的測試案例,直接運行main方法,發(fā)現(xiàn)原本能夠被加載的aizerCore,發(fā)現(xiàn)在ioc容器中找不到了。

public static void main(String[] args) throws IOException {
    ConfigurableApplicationContext ac=SpringApplication.run(SpringBootStudyApplication.class, args);
    aizerCore Myc=ac.getBean(aizerCore.class);
    System.out.println(Myc.study());
}

在當前工程中指定的包com.aizeredu下創(chuàng)建一個TestClass以后,再運行上面這段代碼,程序能夠正常執(zhí)行

三、手寫Starter

我們通過手寫Starter來加深對于自動裝配的理解

1.創(chuàng)建一個Maven項目,quick-starter

定義相關的依賴

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>2.1.6.RELEASE</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.56</version>
    <!-- 可選 -->
    <optional>true</optional>
</dependency>

2.定義Formate接口

定義的格式轉換的接口,并且定義兩個實現(xiàn)類

public interface FormatProcessor {
    /**
     * 定義一個格式化的方法
     * @param obj
     * @param <T>
     * @return
     */
    <T> String formate(T obj);
}
public class JsonFormatProcessor implements FormatProcessor {
    @Override
    public <T> String formate(T obj) {
        return "JsonFormatProcessor:" + JSON.toJSONString(obj);
    }
}
public class StringFormatProcessor implements FormatProcessor {
    @Override
    public <T> String formate(T obj) {
        return "StringFormatProcessor:" + obj.toString();
    }
}

3.定義相關的配置類

首先定義格式化加載的Java配置類

@Configuration
public class FormatAutoConfiguration {

    @ConditionalOnMissingClass("com.alibaba.fastjson.JSON")
    @Bean
    @Primary // 優(yōu)先加載
    public FormatProcessor stringFormatProcessor(){
        return new StringFormatProcessor();
    }

    @ConditionalOnClass(name="com.alibaba.fastjson.JSON")
    @Bean
    public FormatProcessor jsonFormatProcessor(){
        return new JsonFormatProcessor();
    }
}

定義一個模板工具類

public class HelloFormatTemplate {

    private FormatProcessor formatProcessor;


    public HelloFormatTemplate(FormatProcessor processor){
        this.formatProcessor = processor;
    }

    public <T> String doFormat(T obj){
        StringBuilder builder = new StringBuilder();
        builder.append("Execute format : ").append("<br>");
        builder.append("Object format result:" ).append(formatProcessor.formate(obj));
        return builder.toString();
    }
}

再就是整合到SpringBoot中去的Java配置類

@Configuration
@Import(FormatAutoConfiguration.class)
public class HelloAutoConfiguration {

    @Bean
    public HelloFormatTemplate helloFormatTemplate(FormatProcessor formatProcessor){
        return new HelloFormatTemplate(formatProcessor);
    }
}

4.創(chuàng)建spring.factories文件

在resources下創(chuàng)建META-INF目錄,再在其下創(chuàng)建spring.factories文件

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  org.aizeredu.autoconfiguration.HelloAutoConfiguration

install 打包,然后就可以在SpringBoot項目中依賴改項目來操作了。

5.測試

在SpringBoot中引入依賴

<dependency>
    <groupId>org.example</groupId>
    <artifactId>format-spring-boot-starter</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

在controller中使用

@RestController
public class UserController {

    @Autowired
    private HelloFormatTemplate helloFormatTemplate;

    @GetMapping("/format")
    public String format(){
        User user = new User();
        user.setName("BoBo");
        user.setAge(18);
        return helloFormatTemplate.doFormat(user);
    }
}

6.自定義Starter關聯(lián)配置信息

有些情況下我們可以需要用戶在使用的時候動態(tài)的傳遞相關的配置信息,比如Redis的Ip,端口等等,這些信息顯然是不能直接寫到代碼中的,這時我們就可以通過SpringBoot的配置類來實現(xiàn)。

首先引入依賴支持

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <version>2.2.6.RELEASE</version>
    <optional>true</optional>
</dependency>

然后創(chuàng)建對應的屬性類

@ConfigurationProperties(prefix = HelloProperties.HELLO_FORMAT_PREFIX)
public class HelloProperties {

    public static final String HELLO_FORMAT_PREFIX="aizer.hello.format";

    private String name;

    private Integer age;

    private Map<String,Object> info;

    public Map<String, Object> getInfo() {
        return info;
    }

    public void setInfo(Map<String, Object> info) {
        this.info = info;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

然后再Java配置類中關聯(lián)

@Configuration
@Import(FormatAutoConfiguration.class)
@EnableConfigurationProperties(HelloProperties.class)
public class HelloAutoConfiguration {

    @Bean
    public HelloFormatTemplate helloFormatTemplate(HelloProperties helloProperties,FormatProcessor formatProcessor){
        return new HelloFormatTemplate(helloProperties,formatProcessor);
    }
}

調整模板方法

public class HelloFormatTemplate {

    private FormatProcessor formatProcessor;

    private HelloProperties helloProperties;

    public HelloFormatTemplate(HelloProperties helloProperties,FormatProcessor processor){
        this.helloProperties = helloProperties;
        this.formatProcessor = processor;
    }

    public <T> String doFormat(T obj){
        StringBuilder builder = new StringBuilder();
        builder.append("Execute format : ").append("<br>");
        builder.append("HelloProperties:").append(formatProcessor.formate(helloProperties.getInfo())).append("<br>");
        builder.append("Object format result:" ).append(formatProcessor.formate(obj));
        return builder.toString();
    }
}

增加提示

在這個工程的META-INF/下創(chuàng)建一個additional-spring-configuration-metadata.json,這個是設置屬性的提示類型

{
  "properties": [
    {
      "name": "aizer.hello.format.name",
      "type": "java.lang.String",
      "description": "賬號信息",
      "defaultValue": "root"
    },{
      "name": "aizer.hello.format.age",
      "type": "java.lang.Integer",
      "description": "年齡",
      "defaultValue": 18
    }
  ]
}
protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {
		if (!isEnabled(annotationMetadata)) {
			return EMPTY_ENTRY;
		}
		AnnotationAttributes attributes = getAttributes(annotationMetadata);
        // 加載當前系統(tǒng)下 META-INF/spring.factories 文件中聲明的配置類
		List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);
        // 移除掉重復的
		configurations = removeDuplicates(configurations);
        // 移除掉顯示排除的
		Set<String> exclusions = getExclusions(annotationMetadata, attributes);
		checkExcludedClasses(configurations, exclusions);
		configurations.removeAll(exclusions);
        // 過濾掉不需要載入的配置類
		configurations = getConfigurationClassFilter().filter(configurations);
		fireAutoConfigurationImportEvents(configurations, exclusions);
		return new AutoConfigurationEntry(configurations, exclusions);
	}

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • SpringBoot整合dataworks的實現(xiàn)過程

    SpringBoot整合dataworks的實現(xiàn)過程

    這篇文章主要介紹了SpringBoot整合dataworks的實現(xiàn)過程,實現(xiàn)主要是編寫工具類,如果需要則可以配置成SpringBean,注入容器即可使用,需要的朋友可以參考下
    2022-08-08
  • IDEA打包應用程序的教程圖解

    IDEA打包應用程序的教程圖解

    這篇文章主要介紹了IDEA打包應用程序的教程,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-07-07
  • SpringBoot如何指定某些類優(yōu)先啟動

    SpringBoot如何指定某些類優(yōu)先啟動

    這篇文章主要介紹了SpringBoot如何指定某些類優(yōu)先啟動,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09
  • Java適配器模式定義與用法示例

    Java適配器模式定義與用法示例

    這篇文章主要介紹了Java適配器模式定義與用法,結合具體實例形式分析了java適配器模式的功能、組成、定義、使用方法及適配程度等,需要的朋友可以參考下
    2017-06-06
  • 一文掌握IDEA中的Maven集成與創(chuàng)建

    一文掌握IDEA中的Maven集成與創(chuàng)建

    maven是用來幫助我們快速搭建項目結構與開發(fā)環(huán)境的好工具,這篇文章主要介紹了一文掌握IDEA中的Maven集成與創(chuàng)建,需要的朋友可以參考下
    2023-02-02
  • 基于SpringBoot bootstrap.yml配置未生效的解決

    基于SpringBoot bootstrap.yml配置未生效的解決

    這篇文章主要介紹了基于SpringBoot bootstrap.yml配置未生效的解決方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-10-10
  • Java 入門圖形用戶界面設計之列表框JList

    Java 入門圖形用戶界面設計之列表框JList

    圖形界面(簡稱GUI)是指采用圖形方式顯示的計算機操作用戶界面。與早期計算機使用的命令行界面相比,圖形界面對于用戶來說在視覺上更易于接受,本篇精講Java語言中關于圖形用戶界面的列表框JList
    2022-02-02
  • SpringBoot中靜態(tài)資源處理的7個技巧分享

    SpringBoot中靜態(tài)資源處理的7個技巧分享

    在Web應用開發(fā)中,靜態(tài)資源(如CSS、JavaScript、圖片等)的處理是一個基礎但重要的環(huán)節(jié),本文將介紹SpringBoot中7種靜態(tài)資源處理技巧,希望對大家有所幫助
    2025-05-05
  • SpringBoot3和mybatis-plus整合出現(xiàn)的問題解決辦法

    SpringBoot3和mybatis-plus整合出現(xiàn)的問題解決辦法

    SpringBoot和MybatisPlus的整合可以讓我們更加方便地進行數據庫操作,這篇文章主要給大家介紹了關于SpringBoot3和mybatisplus整合出現(xiàn)的一些問題的相關資料,需要的朋友可以參考下
    2024-01-01
  • 查找native方法的本地實現(xiàn)函數native_function詳解

    查找native方法的本地實現(xiàn)函數native_function詳解

    JDK開放給用戶的源碼中隨處可見Native方法,被Native關鍵字聲明的方法說明該方法不是以Java語言實現(xiàn)的,而是以本地語言實現(xiàn)的,Java可以直接拿來用。這里介紹下查找native方法的本地實現(xiàn)函數native_function,感興趣的朋友跟隨小編一起看看吧
    2021-12-12

最新評論