【吃透Java手写】3-SpringBoot-简易版-源码解析

【吃透Java手写】SpringBoot-简易版-源码解析

  • 1 SpringbootDemo
  • 2 准备工作
    • 2.1 Springboot-my
      • 2.1.1 依赖
      • 2.1.2 @SpringBootApplication
      • 2.1.3 SJBSpringApplication
        • 2.1.3.1 run方法
    • 2.2 Springboot-user
      • 2.2.1 依赖
      • 2.2.2 UserController
      • 2.2.3 UserApplication
    • 2.3 分析run方法的逻辑
      • 2.3.1 创建Spring容器
      • 2.3.2 启动Tomcat
    • 2.4 启动UserApplication
  • 3 功能拓展
    • 3.1 创建WebServer
    • 3.2 获取对应服务的WebServer
    • 3.3 条件注解@SJBConditionalOnClass
    • 3.4 自动配置类
    • 3.5 发现自动配置类
      • 3.5.1 方法一 直接@Import
      • 3.5.2 方法二 使用SPI
      • 3.5.3 spring.factories源码解析


1 SpringbootDemo

引入依赖

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.6.2</version></dependency>
</dependencies>

最简单的SpringbootDemo的只包含启动类

在这里插入图片描述

com.zhouyu.MyApplication:

@SpringBootApplication
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}

我们手写自然要模拟MyApplication这个启动类所做的事情以及@SpringBootApplication所做的事情

2 准备工作

两个包:

  1. springboot模块,表示springboot框架的源码实现
  2. user包,表示用户业务系统,用来写业务代码来测试我们所模拟出来的SpringBoot

2.1 Springboot-my

2.1.1 依赖

SpringBoot是基于的Spring,所以我们要依赖Spring,然后我希望我们模拟出来的SpringBoot也支持Spring MVC的那一套功能,所以也要依赖Spring MVC,包括Tomcat等,所以在Springboot-my模块中要添加以下依赖:

<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.18</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>5.3.18</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.18</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version></dependency><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-core</artifactId><version>9.0.60</version></dependency>
</dependencies>

我们在真正使用SpringBoot时,核心会用到SpringBoot一个类和注解:

  1. @SpringBootApplication,这个注解是加在应用启动类上的,也就是main方法所在的类
  2. SpringApplication,这个类中有个run()方法,用来启动SpringBoot应用的

所以我们也来模拟实现他们。

2.1.2 @SpringBootApplication

创建org.springboot.SJBSpringBootApplication

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Configuration
@ComponentScan
public @interface SJBSpringBootApplication {
}

2.1.3 SJBSpringApplication

2.1.3.1 run方法

源码:

public static ConfigurableApplicationContext run(Class<?> primarySource, String... args) {return run(new Class[]{primarySource}, args);
}
  • String... args:可变参数是为了让通过jar包启动的项目可以指定参数,比如-value=xxx等

我们模拟暂时不考虑这些,只保留最基础的功能

创建org.springboot.SJBSpringApplication

public class SJBSpringApplication {public static void run(Class<?> primarySource, String... args) {}
}

2.2 Springboot-user

我们模拟实现的是SpringBoot,而不是SpringMVC,所以我直接在user包下定义了UserController,最终我希望能运行UserApplication中的main方法,就直接启动了项目,并能在浏览器中正常的访问到UserController中的某个方法。

2.2.1 依赖

引入刚刚的依赖以及Springboot-my的基础依赖

<dependencies><dependency><groupId>org.example</groupId><artifactId>Springboot-my</artifactId><version>1.0-SNAPSHOT</version></dependency>
</dependencies>

2.2.2 UserController

创建com.sjb.user.controller.UserController

@RestController
public class UserController {@GetMapping("/test")public String test() {return "sjb123";}
}

2.2.3 UserApplication

创建com.sjb.user.UserApplication,使用我们刚刚创建的SJBSpringApplication启动类以及SJBSpringBootApplication注解

@SJBSpringBootApplication
public class UserApplication {public static void main(String[] args) {SJBSpringApplication.run(UserApplication.class, args);}
}

2.3 分析run方法的逻辑

首先,我们希望run方法一旦执行完,我们就能在浏览器中访问到UserController,那势必在run方法中要启动Tomcat,通过Tomcat就能接收到请求了。

大家如果学过Spring MVC的底层原理就会知道,在SpringMVC中有一个Servlet非常核心,那就是DispatcherServlet,这个DispatcherServlet需要绑定一个Spring容器,因为DispatcherServlet接收到请求后,就会从所绑定的Spring容器中找到所匹配的Controller,并执行所匹配的方法。

所以,在run方法中,我们要实现的逻辑如下:

  1. 创建一个Spring容器
  2. 创建Tomcat对象
  3. 生成DispatcherServlet对象,并且和前面创建出来的Spring容器进行绑定
  4. 将DispatcherServlet添加到Tomcat中
  5. 启动Tomcat

2.3.1 创建Spring容器

public static void run(Class<?> configClazz) {AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();applicationContext.register(configClazz);applicationContext.refresh();
}

我们创建的是一个AnnotationConfigWebApplicationContext容器,并且把run方法传入进来的class作为容器的配置类,比如在UserApplication的run方法中,我们就是把2.2.3中的UserApplication.class传入到了run方法中,最终UserApplication就是所创建出来的Spring容器的配置类,并且由于UserApplication类上有@SJBSpringBootApplication注解,而@SJBSpringBootApplication注解的定义上又存在@ComponentScan注解,所以AnnotationConfigWebApplicationContext容器在执行refresh时,就会解析UserApplication这个配置类,从而发现定义了@ComponentScan注解,也就知道了要进行扫描,只不过扫描路径为空,而AnnotationConfigWebApplicationContext容器会处理这种情况,如果扫描路径会空,则会将UserApplication所在的包路径做为扫描路径,从而就会扫描到UserController。

RestController:

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {@AliasFor(annotation = Controller.class)String value() default "";
}

Controller

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {@AliasFor(annotation = Component.class)String value() default "";
}

所以Spring容器创建完之后,容器内部就拥有了UserController这个Bean。

2.3.2 启动Tomcat

我们用的是Embed-Tomcat,也就是内嵌的Tomcat,真正的SpringBoot中也用的是内嵌的Tomcat,而对于启动内嵌的Tomcat,也并不麻烦

在org.springboot.SJBSpringApplication#run中新建startTomcat方法

public static void startTomcat(WebApplicationContext applicationContext){Tomcat tomcat = new Tomcat();Server server = tomcat.getServer();Service service = server.findService("Tomcat");Connector connector = new Connector();connector.setPort(8081);Engine engine = new StandardEngine();engine.setDefaultHost("localhost");Host host = new StandardHost();host.setName("localhost");String contextPath = "";Context context = new StandardContext();context.setPath(contextPath);context.addLifecycleListener(new Tomcat.FixContextListener());host.addChild(context);engine.addChild(host);service.setContainer(engine);service.addConnector(connector);tomcat.addServlet(contextPath, "dispatcher", new DispatcherServlet(applicationContext));context.addServletMappingDecoded("/*", "dispatcher");try {tomcat.start();} catch (LifecycleException e) {e.printStackTrace();}
}

代码虽然看上去比较多,但是逻辑并不复杂,比如配置了Tomcat绑定的端口为8081,后面向当前Tomcat中添加了DispatcherServlet,并设置了一个Mapping关系,最后启动,其他代码则不用太过关心。

而且在构造DispatcherServlet对象时,传入了一个ApplicationContext对象,也就是一个Spring容器,就是我们前文说的,DispatcherServlet对象和一个Spring容器进行绑定。

接下来,我们只需要在run方法中,调用startTomcat即可:

public static void run(Class<?> configClazz) {AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();applicationContext.register(configClazz);applicationContext.refresh();startTomcat(applicationContext);
}

2.4 启动UserApplication

输出

5月 06, 2024 1:40:03 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-nio-8081"]
5月 06, 2024 1:40:03 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Tomcat]
5月 06, 2024 1:40:03 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet engine: [Apache Tomcat/9.0.60]
5月 06, 2024 1:40:03 下午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
警告: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [111] milliseconds.
5月 06, 2024 1:40:03 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-8081"]

显示启动成功,访问http://localhost:8081/test

在这里插入图片描述

成功访问到并输出

3 功能拓展

虽然我们前面已经实现了一个比较简单的SpringBoot,不过我们可以继续来扩充它的功能,比如现在我有这么一个需求,这个需求就是我现在不想使用Tomcat了,而是想要用Jetty,那该怎么办?

我们前面代码中默认启动的是Tomcat,那我现在想改成这样子:

  1. 如果项目中有Tomcat的依赖,那就启动Tomcat
  2. 如果项目中有Jetty的依赖就启动Jetty
  3. 如果两者都没有则报错
  4. 如果两者都有也报错

这个逻辑希望SpringBoot自动帮我实现,对于程序员用户而言,只要在Pom文件中添加相关依赖就可以了,想用Tomcat就加Tomcat依赖,想用Jetty就加Jetty依赖。

那SpringBoot该如何实现呢?

3.1 创建WebServer

我们知道,不管是Tomcat还是Jetty,它们都是应用服务器,或者是Servlet容器,所以我们可以定义接口来表示它们,这个接口叫做WebServer(别问我为什么叫这个,因为真正的SpringBoot源码中也叫这个)。

创建org.springboot.WebServer,并且在这个接口中定义一个start方法:

public interface WebServer { public void start();	
}

有了WebServer接口之后,就针对Tomcat和Jetty提供两个实现类:

创建org.springboot.TomcatWebServer实现类和org.springboot.JettyWebServer实现类

public class TomcatWebServer implements WebServer{@Overridepublic void start() {System.out.println("TomcatWebServer start...");}
}
public class JettyWebServer implements WebServer{@Overridepublic void start() {System.out.println("JettyWebServer start...");}
}

并且在Springboot-my模块中添加Jetty的依赖

<dependency><groupId>org.eclipse.jetty</groupId><artifactId>jetty-server</artifactId><version>9.4.43.v20210629</version>
</dependency>

3.2 获取对应服务的WebServer

而在SJBSpringApplication中的run方法中,我们就要去获取对应的WebServer,然后启动对应的webServer,代码为:

public static void run(Class clazz){AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();applicationContext.register(clazz);applicationContext.refresh();WebServer webServer = getWebServer(applicationContext);webServer.start();
}public static WebServer getWebServer(AnnotationConfigWebApplicationContext applicationContext){return null;
}

这样,我们就只需要在getWebServer方法中去判断到底该返回TomcatWebServer还是JettyWebServer。

前面提到过,我们希望根据项目中的依赖情况,来决定到底用哪个WebServer,所以直接用SpringBoot中的源码实现方式来模拟了。

3.3 条件注解@SJBConditionalOnClass

创建org.springboot.SJBConditionalOnClass注解

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Conditional(SJBOnClassCondition.class)
public @interface SJBConditionalOnClass {String value() default "";
}
  • @Conditional注解是从spring4.0才有的,可以用在任何类型或者方法上面,通过@Conditional注解可以配置一些条件判断,当所有条件都满足的时候,被@Conditional标注的目标才会被spring容器处理。

  • Condition接口:用来表示条件判断的接口,源码如下:

    @FunctionalInterface
    public interface Condition {/*** 判断条件是否匹配* context:条件判断上下文*/boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata);}
    
  • @Conditional使用的3步骤:

    1. 自定义一个类,实现Condition或ConfigurationCondition接口,实现matches方法

    2. 在目标对象上使用@Conditional注解,并指定value的指为自定义的Condition类型

    3. 启动spring容器加载资源,此时@Conditional就会起作用了

注意核心为@Conditional(SJBOnClassCondition.class)中的SJBOnClassCondition,因为它才是真正得条件逻辑:

public class SJBOnClassCondition implements Condition {@Overridepublic boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {Map<String, Object> annotationAttributes =metadata.getAnnotationAttributes(SJBConditionalOnClass.class.getName());String className = (String) annotationAttributes.get("value");try {context.getClassLoader().loadClass(className);return true;} catch (ClassNotFoundException e) {return false;}}
}

具体逻辑为,拿到@SJBConditionalOnClass中的value属性,然后用类加载器进行加载,如果加载到了所指定的这个类,那就表示符合条件,如果加载不到,则表示不符合条件。

并且进行可选依赖配置

将Spring-my中的依赖修改

<dependency><groupId>org.eclipse.jetty</groupId><artifactId>jetty-server</artifactId><version>9.4.43.v20210629</version><optional>true</optional>
</dependency>

添加<optional>true</optional>这样只是Spring-user只依赖tomcat,如果要依赖jetty

则修改为

<dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.18</version><exclusions><exclusion><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-core</artifactId></exclusion></exclusions>
</dependency><!--        <dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-core</artifactId><version>9.0.60</version>
</dependency>-->
<dependency><groupId>org.eclipse.jetty</groupId><artifactId>jetty-server</artifactId><version>9.4.43.v20210629</version>
</dependency>

3.4 自动配置类

UserApplication的@SJBSpringBootApplication只会扫描com.sjb.user下的包,自动配置类并没有作为Bean放入容器内

有了条件注解,我们就可以来使用它了,那如何实现呢?这里就要用到自动配置类的概念

创建org.springboot.WebServiceAutoConfiguration

@Configuration
public class WebServiceAutoConfiguration {@Bean@SJBConditionalOnClass("org.apache.catalina.startup.Tomcat")public TomcatWebServer tomcatWebServer(){return new TomcatWebServer();}@Bean@SJBConditionalOnClass("org.eclipse.jetty.server.Server")public JettyWebServer jettyWebServer(){return new JettyWebServer();}
}

这个代码还是比较简单的,通过一个WebServiceAutoConfiguration的Spring配置类,在里面定义了两个Bean,一个TomcatWebServer,一个JettyWebServer,不过这两个要生效的前提是符合当前所指定的条件,比如:

  1. 只有存在"org.apache.catalina.startup.Tomcat"类,那么才有TomcatWebServer这个Bean
  2. 只有存在"org.eclipse.jetty.server.Server"类,那么才有TomcatWebServer这个Bean

并且我们只需要在SJBSpringApplication中getWebServer方法,如此实现:

public static WebServer getWebServer(ApplicationContext applicationContext){// key为beanName, value为Bean对象Map<String, WebServer> webServers = applicationContext.getBeansOfType(WebServer.class);if (webServers.isEmpty()) {throw new NullPointerException();}if (webServers.size() > 1) {throw new IllegalStateException();}// 返回唯一的一个return webServers.values().stream().findFirst().get();
}

这样整体SpringBoot启动逻辑就是这样的:

  1. 创建一个AnnotationConfigWebApplicationContext容器
  2. 解析UserApplication类,然后进行扫描
  3. 通过getWebServer方法从Spring容器中获取WebServer类型的Bean
  4. 调用WebServer对象的start方法

有了以上步骤,我们还差了一个关键步骤,就是Spring要能解析到WebServiceAutoConfiguration这个自动配置类,因为不管这个类里写了什么代码,Spring不去解析它,那都是没用的,此时我们需要SpringBoot在run方法中,能找到WebServiceAutoConfiguration这个配置类并添加到Spring容器中。

UserApplication是Spring的一个配置类,但是UserApplication是我们传递给SpringBoot,从而添加到Spring容器中去的,而WebServiceAutoConfiguration就需要SpringBoot去自动发现,而不需要程序员做任何配置才能把它添加到Spring容器中去,而且要注意的是,Spring容器扫描也是扫描不到WebServiceAutoConfiguration这个类的,因为我们的扫描路径是"com.sjb.user",而WebServiceAutoConfiguration所在的包路径为"org.springboot"。

3.5 发现自动配置类

3.5.1 方法一 直接@Import

直接在org.springboot.SJBSpringBootApplication注解上加上完成自动装配

@Import(WebServiceAutoConfiguration.class)

3.5.2 方法二 使用SPI

SpringBoot中自己实现了一套SPI机制,也就是我们熟知的spring.factories文件,那么我们模拟就不搞复杂了,就直接用JDK自带的SPI机制。

因为针对后面所有的自动配置类,一个一个导入不现实,所以就需要使用SPI。

然后需要在resources目录下新建META-INF/services目录,并且在这个目录下新建一个与上述接口的全限定名一致的文件org.springboot.AutoConfiguration,在这个文件中写入接口的实现类的全限定名:

org.springboot.WebServiceAutoConfiguration

在这里插入图片描述

SPI的配置就完成了,相当于通过org.springboot.AutoConfiguration文件配置了springboot中所提供的配置类。

并且提供一个接口:

public interface AutoConfiguration {
}

并且WebServiceAutoConfiguration实现该接口:

@Configuration
public class WebServiceAutoConfiguration implements AutoConfiguration{@Bean@SJBConditionalOnClass("org.apache.catalina.startup.Tomcat")public TomcatWebServer tomcatWebServer(){return new TomcatWebServer();}@Bean@SJBConditionalOnClass("org.eclipse.jetty.server.Server")public JettyWebServer jettyWebServer(){return new JettyWebServer();}
}

然后我们再利用spring中的@Import技术来导入这些配置类,我们在@SJBSpringBootApplication的定义上增加如下代码:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Configuration
@ComponentScan
@Import(SJBImportSelect.class)
public @interface SJBSpringBootApplication {
}

引入的SJBImportSelect如下,通过serviceLoader加载实现类并调用:

public class SJBImportSelect implements DeferredImportSelector {@Overridepublic String[] selectImports(AnnotationMetadata importingClassMetadata) {ServiceLoader<AutoConfiguration> serviceLoader = ServiceLoader.load(AutoConfiguration.class);List<String> list = new ArrayList<>();for (AutoConfiguration autoConfiguration : serviceLoader) {list.add(autoConfiguration.getClass().getName());}return list.toArray(new String[0]);}
}

ServiceLoader这个类的源码如下:

public final class ServiceLoader<S> implements Iterable<S> {//扫描目录前缀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 java.util.ServiceLoader.LazyIterator lookupIterator;// 私有内部类,提供对所有的service的类的加载与实例化private class LazyIterator implements Iterator<S> {Class<S> service;ClassLoader loader;Enumeration<URL> configs = null;String nextName = null;//...private boolean hasNextService() {if (configs == null) {try {//获取目录下所有的类String fullName = PREFIX + service.getName();if (loader == null)configs = ClassLoader.getSystemResources(fullName);elseconfigs = loader.getResources(fullName);} catch (IOException x) {//...}//....}}private S nextService() {String cn = nextName;nextName = null;Class<?> c = null;try {//反射加载类c = Class.forName(cn, false, loader);} catch (ClassNotFoundException x) {}try {//实例化S p = service.cast(c.newInstance());//放进缓存providers.put(cn, p);return p;} catch (Throwable x) {//..}//..}}
}

在这里插入图片描述

这就完成了从org.springboot.AutoConfiguration文件中获取自动配置类的名字,并导入到Spring容器中,从而Spring容器就知道了这些配置类的存在,而对于user项目而言,是不需要修改代码的。

3.5.3 spring.factories源码解析

@ComponentScan 注解只能扫描 Spring Boot 项目包内的 bean 并注册到 Spring 容器中,项目依赖包中的 bean 不会被扫描和注册。此时,我们需要使用 @EnableAutoConfiguration 注解来注册项目依赖包中的 bean。而 spring.factories 文件,可用来记录项目包外需要注册的 bean 类名。

在这里插入图片描述

EnableAutoConfiguration注解:

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import({AutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration {String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";Class<?>[] exclude() default {};String[] excludeName() default {};
}

导入的类AutoConfigurationImportSelector.class:

根据接口获取其接口类的名称,这个方法返回的是类名的列表,获取所有的依赖包组成Map

public static List<String> loadFactoryNames(Class<?> factoryType, @Nullable ClassLoader classLoader) {ClassLoader classLoaderToUse = classLoader;if (classLoader == null) {classLoaderToUse = SpringFactoriesLoader.class.getClassLoader();}String factoryTypeName = factoryType.getName();return (List)loadSpringFactories(classLoaderToUse).getOrDefault(factoryTypeName, Collections.emptyList());
}

在org.springframework.core.io.support.SpringFactoriesLoader#loadSpringFactories中

然后从Map集合中找到Value,找他的META-INF/spring.factories,

private static Map<String, List<String>> loadSpringFactories(ClassLoader classLoader) {Map<String, List<String>> result = (Map)cache.get(classLoader);if (result != null) {return result;} else {Map<String, List<String>> result = new HashMap();try {Enumeration<URL> urls = classLoader.getResources("META-INF/spring.factories");while(urls.hasMoreElements()) {URL url = (URL)urls.nextElement();UrlResource resource = new UrlResource(url);

spring.factories的是通过Properties解析得到的,所以我们在写文件中的内容都是安装下面这种方式配置的:

com.xxx.interface=com.xxx.classname

当在Maven中引入依赖时,Maven会负责下载并管理这些依赖包,但并不涉及具体的配置和集成。而当你在项目中需要使用Spring框架来管理组件、配置和依赖时,你可能需要在META-INF/spring.factories文件中注册一些类或者配置,以便Spring框架在应用启动时自动扫描并按照这些配置进行初始化。

所以,Maven用于管理依赖,而META-INF/spring.factories用于Spring框架的自动化配置和集成,它们可以配合使用来构建一个完整的项目。

需不需要META-INF这取决于依赖包本身的设计和功能。有些依赖包可能已经完全集成了Spring框架,并且在其内部已经做好了相应的自动化配置,因此你只需引入依赖即可直接在Spring项目中使用,而不需要手动添加额外的配置。

另一方面,有些依赖包可能提供了一些Spring框架的扩展或者功能,但并没有直接与Spring框架进行深度集成。在这种情况下,你可能需要在项目中手动配置一些内容,例如在META-INF/spring.factories文件中添加一些配置,以便Spring框架能够识别和使用这些扩展或功能。

因此,需要在META-INF中添加配置的情况取决于依赖包本身的特性以及与Spring框架的集成程度。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/3030209.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

第二章 checkpoint机制 - 介绍

Checkpoint介绍 1、介绍 PostgreSQL基于DRAMHDD/SSD两层存储架构&#xff0c;所有读写都在DRAM中进行。由于数据写大部分都是随机的&#xff0c;为提高数据库性能&#xff0c;通过写前日志WAL将所有修改都记录到日志中&#xff0c;事务提交时&#xff0c;将日志持久化到磁盘即…

Java入门基础学习笔记12——变量详解

变量详解&#xff1a; 变量里的数据在计算机中的存储原理。 二进制&#xff1a; 只有0和1&#xff0c; 按照逢2进1的方式表示数据。 十进制转二进制的算法&#xff1a; 除二取余法。 6是110 13是1101 计算机中表示数据的最小单元&#xff1a;一个字节&#xff08;byte&…

通俗的理解网关的概念的用途(一)

网关这个概念最早使用于网络&#xff0c;但在当今的智能设备/产品界中&#xff0c;硬生生的被产品人也搞出来一个“网关”的概念&#xff0c;这让早期的咱们这些只知道网络中的网关的人&#xff0c;听得稀里糊涂的。比如智能门锁、安防摄像头等&#xff0c;在产品的使用和介绍中…

java JMH 学习

JMH 是什么&#xff1f; JMH&#xff08;Java Microbenchmark Harness&#xff09;是一款专用于代码微基准测试的工具集&#xff0c;其主要聚焦于方法层面的基准测试&#xff0c;精度可达纳秒级别。此工具由 Oracle 内部负责实现 JIT 的杰出人士编写&#xff0c;他们对 JIT 及…

服务号转订阅号的操作步骤(吐血整理)

服务号和订阅号有什么区别&#xff1f;服务号转为订阅号有哪些作用&#xff1f;我们知道&#xff0c;公众号分为服务号和订阅号两种&#xff0c;服务号只能企业才可以申请&#xff0c;订阅号是企业和个人都可以申请。其中最大的区别是服务号一个月只能发送4次群发&#xff0c;但…

shopro商城 源码搭建/部署/上线/运营/售后/更新

基于Fastadmin和Uniapp进行开发的多平台&#xff08;微信公众号、微信小程序、H5网页、Android-App、IOS-App&#xff09;购物商城&#xff0c;拥有强大的店铺装修、自定义模板、路由同步、多端支付&#xff08;微信&#xff0c;支付宝&#xff09;、多规格商品、运费模板、多地…

我在洛杉矶采访到了亚马逊云全球首席信息官CISO(L11)!

在本次洛杉矶举办的亚马逊云Re:Inforce全球安全大会中&#xff0c;小李哥作为亚马逊大中华区开发者社区和自媒体代表&#xff0c;跟着亚马逊云安全产品团队采访了亚马逊云首席信息安全官(CISO)CJ Moses、亚马逊副总裁Eric Brandwine和亚马逊云首席高级安全工程师Becky Weiss。 …

【学习AI-相关路程-工具使用-自我学习-Ubuntucudavisco-开发工具尝试-基础样例 (2)】

【学习AI-相关路程-工具使用-自我学习-cuda&visco-开发工具尝试-基础样例 &#xff08;2&#xff09;】 1、前言2、环境说明3、总结说明4、工具安装0、验证cuda1、软件下载2、插件安装 5、软件设置与编程练习1、创建目录2、编译软件进入目录&创建两个文件3、编写配置文…

可微分矢量图形光栅化用于编辑和学习

图1. 我们引入了一种通过反向传播将光栅和矢量域联系起来的矢量图形可微分光栅化器。可微分光栅化实现了许多新颖的矢量图形应用。&#xff08;a&#xff09;在几何约束下&#xff0c;通过局部优化图像空间度量&#xff08;如不透明度&#xff09;来实现交互式编辑。&#xff0…

如何使用vue脚手架创建项目

前言 使用vue搭建项目的时候&#xff0c;我们可以通过对应的cmd命令去打开脚手架&#xff0c;然后自己配置对应的功能插件 说明&#xff1a; 要使用Vue脚手架创建项目&#xff0c;你需要先确保你已经安装了Node.js和npm&#xff08;Node.js的包管理器&#xff09;。然后&#…

uniapp 版本检查更新

总体来说uniapp的跨平台还是很不错的&#xff0c;虽然里面各种坑要去踩&#xff0c;但是踩坑也是开发人员的必修课和成长路。 这不&#xff0c;今天就来研究了一下版本检查更新就踩到坑了。。。先来看看检查更新及下载、安装的实现。 先来看看页面&#xff1a; 从左到右依次为…

CSRF、XSS攻防原理及解决方案

一、CSRF CSRF 全称叫做&#xff0c;跨站请求伪造(Cross—Site Request Forgery)&#xff0c;顾名思义&#xff0c;攻击者盗用了你的身份&#xff0c;以你的名义发送恶意请求&#xff0c;对服务器来说这个请求是完全合法的&#xff0c;但是却完成了攻击者所期望的一个操作&…

bbr 是真不行

bbr 作为 mimd 实例如何收敛到公平请看 瓶颈带宽的公平收敛&#xff0c;但这只是公平收敛&#xff0c;并不是 buffer 收敛。 上午跟朋友讨论了一个有趣的问题&#xff0c;感觉有必要揭露一下 bbr 的 buffer 不收敛。若不是有 probertt&#xff0c;多流共享瓶颈链路场景下&…

TC377TX 超声波雷达数据更新缓慢问题排查

1、问题表象 通过标定数据查看超声波雷达实时的距离大小,发现距离并没有实时更新,而是在实际值与默认值之间跳变,更新十分缓慢。   泊车功能必须依赖超声波雷达测距来实现,当雷达数据更新缓慢时,会导致泊车失败。 2、超声波雷达测距实现原理 MCU给超声波雷达发送一个40…

【SpringBoot整合系列】SpringBoot整合RabbitMQ-消息可靠性

目录 确保消息的可靠性RabbitMQ 消息发送可靠性分析解决方案开启事务机制发送方确认机制单条消息处理消息批量处理 失败重试自带重试机制业务重试 RabbitMQ 消息消费可靠性如何保证消息在队列RabbitMQ 的消息消费&#xff0c;整体上来说有两种不同的思路&#xff1a;确保消费成…

Python专题:十、字典(1)

数据类型:字典,是一个集合性质的数据类型 字典的初始化 字典{关键字:数值} 新增元素 修改元素 字典元素访问 字典[关键字} in 操作符 字典关键字检测 字典元素遍历 ①遍历关键字

ESP32引脚入门指南(六):从理论到实践(UART)

ESP32开发板具有UART0、UART1和UART2三个UART接口&#xff0c;支持异步通信(RS232和RS485)和IrDA速率高达5mbps。这些接口提供了丰富的串行通信选项&#xff0c;允许与各种设备进行全双工通信。 UART接口概述与引脚配置 UART 是一种全双工通信协议&#xff0c;允许数据同时在…

JAVA获取application.yml配置文件的属性值

application.yml配置参数 方式一&#xff1a;使用Value方式(常用) 语法 Value("${配置文件中的key:默认值}") Value("${配置文件中的key}")方法1&#xff1a;使用的类文件中定义变量&#xff0c;直接使用变量 import org.springframework.beans.factory.an…

初阶数据结构—顺序表和链表

第一章&#xff1a;线性表 线性表&#xff08;linear list&#xff09;是n个具有相同特性的数据元素的有限序列。 线性表是一种在实际中广泛使用的数据结构&#xff0c;常见的线性表&#xff1a;顺序表、链表、栈、队列、字符串... 线性表在逻辑上是线性结构&#xff0c;也就…

STM32MP157_程序烧录

STM32MP157_程序烧录 说明&#xff1a; 1、使用emmc作为存储媒介&#xff0c;emmc是核心板上的存储颗粒空间有8GB 2、SD卡作为存储媒介&#xff0c;底板上有SD卡的插槽 emmc方式 软件&#xff1a;烧录软件使用STM32CubeProgrammer 连接线&#xff1a;硬件连接线使用type_c数据线…