随笔分类 -  spring 原理

spring 如何实现的相关底层知识
摘要:演示 点击查看代码 public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(A49.class); con 阅读全文
posted @ 2022-07-18 16:47 xy7112 阅读(42) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 // 事件解耦例子 @Configuration public class A48_1 { public static void main(String[] args) { AnnotationConfigApplicationContext context = new Annotat 阅读全文
posted @ 2022-07-18 16:29 xy7112 阅读(40) 评论(0) 推荐(0) 编辑
摘要:演示 点击查看代码 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(A47_1.class); DefaultListableBeanFactory beanFactory = c 阅读全文
posted @ 2022-07-18 16:01 xy7112 阅读(223) 评论(0) 推荐(0) 编辑
摘要:按类型装配的步骤 查看需要的类型是否为 Optional,是,则进行封装(非延迟),否则向下走 查看需要的类型是否为 ObjectFactory 或 ObjectProvider,是,则进行封装(延迟),否则向下走 查看需要的类型(成员或参数)上是否用 @Lazy 修饰,是,则返回代理,否则向下走 阅读全文
posted @ 2022-07-16 15:48 xy7112 阅读(48) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 ConfigurableApplicationContext context = SpringApplication.run(A45.class, args); Bean1 proxy = context.getBean(Bean1.class); /* 1.演示 spring 代理的 阅读全文
posted @ 2022-07-16 14:58 xy7112 阅读(21) 评论(0) 推荐(0) 编辑
摘要:项目中,只需要加入以下依赖即可 在编译期扫描结束 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-indexer</artifactId> <optional>true</optional> 阅读全文
posted @ 2022-07-16 14:46 xy7112 阅读(50) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(A43.class); Bean1 bean1 = (Bean1) context.getBean("bean1"); 阅读全文
posted @ 2022-07-16 14:34 xy7112 阅读(16) 评论(0) 推荐(0) 编辑
摘要:条件装配的底层是本质上是 @Conditional 与 Condition,这两个注解。引入自动配置类时,期望满足一定条件才能被 Spring 管理,不满足则不管理,怎么做呢? 比如条件是【类路径下必须有 dataSource】这个 bean ,怎么做呢? 首先编写条件判断类,它实现 Conditi 阅读全文
posted @ 2022-07-16 13:41 xy7112 阅读(25) 评论(0) 推荐(0) 编辑
摘要:AopAutoConfiguration Spring Boot 是利用了自动配置类来简化了 aop 相关配置 AOP 自动配置类为 org.springframework.boot.autoconfigure.aop.AopAutoConfiguration 可以通过 spring.aop.aut 阅读全文
posted @ 2022-07-15 22:48 xy7112 阅读(91) 评论(0) 推荐(0) 编辑
摘要:Tomcat 基本结构 Server └───Service ├───Connector (协议, 端口) └───Engine └───Host(虚拟主机 localhost) ├───Context1 (应用1, 可以设置虚拟路径, / 即 url 起始路径; 项目磁盘路径, 即 docBase 阅读全文
posted @ 2022-07-15 15:10 xy7112 阅读(36) 评论(0) 推荐(0) 编辑
摘要:阶段一:SpringApplication 构造 点击查看代码 构造源码: public SpringApplication(Class<?>... primarySources) { this(null, primarySources); } public SpringApplication(Re 阅读全文
posted @ 2022-07-14 20:34 xy7112 阅读(28) 评论(0) 推荐(0) 编辑
摘要:步骤1:创建模块,区别在于打包方式选择 war 接下来勾选 Spring Web 支持 步骤2:编写控制器 @Controller public class MyController { @RequestMapping("/hello") public String abc() { System.o 阅读全文
posted @ 2022-07-14 15:25 xy7112 阅读(23) 评论(0) 推荐(0) 编辑
摘要:如果是 linux 环境,用以下命令即可获取 spring boot 的骨架 pom.xml curl -G https://start.spring.io/pom.xml -d dependencies=web,mysql,mybatis -o pom.xml -d dependencies=相关 阅读全文
posted @ 2022-07-14 15:13 xy7112 阅读(31) 评论(0) 推荐(0) 编辑
摘要:当浏览器发送一个请求 http://localhost:8080/hello 后,请求到达服务器,其处理流程是: 服务器提供了 DispatcherServlet,它使用的是标准 Servlet 技术 路径:默认映射路径为 /,即会匹配到所有请求 URL,可作为请求的统一入口,也被称之为前控制器 j 阅读全文
posted @ 2022-07-14 15:07 xy7112 阅读(31) 评论(0) 推荐(0) 编辑
摘要:HandlerMapping 负责建立请求与控制器之间的映射关系 RequestMappingHandlerMapping (与 @RequestMapping 匹配) WelcomePageHandlerMapping (/) BeanNameUrlHandlerMapping (与 bean 的 阅读全文
posted @ 2022-07-14 14:54 xy7112 阅读(27) 评论(0) 推荐(0) 编辑
摘要:我们知道 @ExceptionHandler 只能处理发生在 mvc 流程中的异常,例如控制器内、拦截器内,那么如果是 Filter 出现了异常,如何进行处理呢? 在 Spring Boot 中,是这么实现的: 因为内嵌了 Tomcat 容器,因此可以配置 Tomcat 的错误页面,Filter 与 阅读全文
posted @ 2022-07-09 22:48 xy7112 阅读(277) 评论(0) 推荐(0) 编辑
摘要:演示 与之前的 @ControllerAdvice 中增强类似,分为控制器类中的懒惰解析, 和 @ControllerAdvice 注解标注的配置类中的,ExceptionHandlerExceptionResolver 初始化解析 点击查看代码 public static void main(St 阅读全文
posted @ 2022-07-08 17:33 xy7112 阅读(35) 评论(0) 推荐(0) 编辑
摘要:ExceptionHandlerExceptionResolver 代码参考 点击查看代码 public static void main(String[] args) throws NoSuchMethodException { ExceptionHandlerExceptionResolver 阅读全文
posted @ 2022-07-08 17:17 xy7112 阅读(31) 评论(0) 推荐(0) 编辑
摘要:ResponseBodyAdvice 增强 ResponseBodyAdvice 增强 在整个 HandlerAdapter 调用过程中所处的位置 点击查看代码 @Configuration public class WebConfig { @ControllerAdvice //将所有返回值类型统 阅读全文
posted @ 2022-07-08 17:02 xy7112 阅读(119) 评论(0) 推荐(0) 编辑
摘要:演示 - MessageConverter 的作用 点击查看代码 private static void test4() throws IOException, HttpMediaTypeNotAcceptableException, NoSuchMethodException { MockHttp 阅读全文
posted @ 2022-07-07 22:01 xy7112 阅读(23) 评论(0) 推荐(0) 编辑