2024年3月6日
Servlet 容器详解 Servlet 容器是 Java Web 应用程序的核心组件之一。它负责管理 Servlet 的生命周期、请求分发、会话跟踪等任务。在这篇博客中,我们将详细介绍 Servlet 容器的工作原理和常见实现。 1. Servlet 容器的工作原理 Servlet 容器的工作原理如下: 接收客户端请求:Servlet 容器监听一个或多个端口,等待客户端的请求。 解析请求:Ser……
阅读全文
2024年3月6日
Servlet 基础 Servlet 简介 Servlet(Server Applet)是 J2EE 的内容之一,由 Java 编写的服务器端小程序。它是 web 请求的入口,主要功能在于交互式地(Request 和 Response)浏览和修改数据,生成动态 Web 内容。Servlet 运行于支持 Servlet 的 WEB 容器中,如 Tomcat。从实现上讲,Servle……
阅读全文
2024年3月6日
Spring Security 请求全过程解析 Spring Security 是一款基于 Spring 的安全框架,主要包含认证和授权两大安全模块,和另外一款流行的安全框架 Apache Shiro 相比,它拥有更为强大的功能。Spring Security 也可以轻松的自定义扩展以满足各种需求,并且对常见的 Web 安全攻击提供了防护支持。如果你的 Web 框架选择的是 Spring,那么在安全方面 Spring Security 会……
阅读全文
2024年3月6日
Spring Security 自定义用户认证 在Spring Boot 中开启 Spring Security一节中我们简单地搭建了一个 Spring Boot + Spring Security 的项目,其中登录页、用户名和密码都是由 Spring Security 自动生成的。Spring Security 支持我们自定义认证的过程,如使用自定义的登录页替换默认的登录页,用户信息的获取逻辑、登录成功或失败后的处理逻辑等。这里……
阅读全文
2024年3月6日
SpringSecurity 流程补充 注意: 基于 spring-boot-dependencies:2.7.7 首先需要了解 springboot2.7 升级 Changes to Auto-configuration 以后使用 autoconfigure 进行自动注入 代码地址 io.github.poo0054 启动 我们每次添加 <artifactId>spring-boot-starter-security</artifactId>,启动的时候会有一条类似的日志: Using generated springSecurity password: 1db8eb87-e2ee-4c72-88e7-9b85268c4430 This generated password is for development use……
阅读全文
2024年3月6日
说明 源码阅读仓库: spring-cloud-openfeign 参考资料和需要掌握的知识: SpringBoot 源码分析 Spring 源码分析 Spring Cloud 官网文档 Spring Cloud Commons 官网文档 Spring Cloud OpenFeign 官网文档 Feign 官方文档 Spring Cloud OpenFeign 介绍 Feign 是一个声明式的 Web 服务客户端,它使 Java 编写 Web 服务客户端变得更加容易。其实就是通过 JDK 代理生成接口的代理对象,方法的执行就是执行 Http 请求。而 OpenFeign 的作用是通过自动装配……
阅读全文
2024年3月6日
说明 源码阅读仓库: spring-cloud-gateway 参考资料和需要掌握的知识: Spring WebFlux 源码分析 Spring Cloud Circuit Breaker Spring Cloud Commons Spring Cloud Gateway 官网文档 Spring Cloud Gateway 介绍 功能:接收请求并根据匹配的路由进行转发。 术语: Route: 是路由规则的描述。它由 ID、目标 URI、Predicate 集合和Filter 集合组成。如果 Predicate 为真,则路由匹配。 Predicate: 这是一个 Java 8 函数接口。输……
阅读全文
2024年3月6日
说明 源码阅读仓库: spring-cloud-commons 参考资料和需要掌握的知识: SpringBoot 源码分析 Spring 源码分析 Spring Cloud 官网文档 Spring Cloud Commons 官网文档 Spring Cloud 介绍 SpringCloud 是在 SpringBoot 的基础上构建的。Spring Cloud 以两个库的形式提供了许多特性:Spring Cloud Context 和 Spring Cloud Commons。Spring Cloud Context 为 SpringCloud 应用程序的 ApplicationContext 提供扩展机制(引导上下文、加密、刷新属性和……
阅读全文
2024年3月6日
SpringBootBatch 源码 加载 版本使用 2.7.13 1 2 3 4 5 6 7 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.7.13</version> <scope>import</scope> <type>pom</type> </dependency> spring-autoconfigure-metadata.properties 1 2 3 4 5 6 7 8 9 10 11 12 13 org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration= org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration$DataSourceInitializerConfiguration= org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration$DataSourceInitializerConfiguration.ConditionalOnBean=javax.sql.DataSource org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration$DataSourceInitializerConfiguration.ConditionalOnClass=org.springframework.jdbc.datasource.init.DatabasePopulator org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration.AutoConfigureAfter=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration.ConditionalOnBean=org.springframework.batch.core.launch.JobLauncher org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration.ConditionalOnClass=javax.sql.DataSource,org.springframework.batch.core.launch.JobLauncher org.springframework.boot.autoconfigure.batch.BatchConfigurerConfiguration= org.springframework.boot.autoconfigure.batch.BatchConfigurerConfiguration$JpaBatchConfiguration= org.springframework.boot.autoconfigure.batch.BatchConfigurerConfiguration$JpaBatchConfiguration.ConditionalOnBean= org.springframework.boot.autoconfigure.batch.BatchConfigurerConfiguration$JpaBatchConfiguration.ConditionalOnClass=javax.persistence.EntityManagerFactory org.springframework.boot.autoconfigure.batch.BatchConfigurerConfiguration.ConditionalOnBean=javax.sql.DataSource org.springframework.boot.autoconfigure.batch.BatchConfigurerConfiguration.ConditionalOnClass=org.springframework.transaction.PlatformTransactionManager @EnableBatchProcessing 启动首先添加@EnableBatchProcessing,这个类引入了BatchConfigurationSelector. BatchConfigurationSelector 这里面主要是判断modular决定加载Modula……
阅读全文
2024年3月6日
Spring Boot 自动装配 Author: HuiFer 源码阅读仓库: SourceHot-spring-boot org.springframework.boot.autoconfigure.SpringBootApplication 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) }) public @interface SpringBootApplication { @AliasFor(annotation = EnableAutoConfiguration.class) Class<?>[] exclude() default {}; @AliasFor(annotation = EnableAutoConfiguration.class) String[] excludeName() default {}; @AliasFor(annotation = ComponentScan.class, attribute = "basePackages") String[] scanBasePackages() default {}; @AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses") Class<?>[] scanBasePackageClasses() default {}; @AliasFor(annotation = Configuration.class) boolean proxyBeanMethods() default true; } EnableAutoConfiguration 1 2 3 4 5 6 7 8 9 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @AutoConfigurationPackage @Import(AutoConfigurationImportSelector.class) public @interface EnableAutoConfiguration { } AutoConfigurationImportSelector 类图 getAutoConfigurationMetadata() 1 2 3 4……
阅读全文