原理 假设有两个外部的第三方配置类: static class OuterBean1{} static class OuterBean2{} /** * 外部配置类1 */ @Configuration static class OuterConfig1{ @Bean public OuterBean1 outerBean1(){ return new OuterBean1(); } } /** * 外部配置类2 */ @Configuration static class Out…
原理 假设有两个外部的第三方配置类: static class OuterBean1{} static class OuterBean2{} /** * 外部配置类1 */ @Configuration static class OuterConfig1{ @Bean public OuterBean1 outerBean1(){ return new OuterBean1(); } } /** * 外部配置类2 */ @Configuration static class Out…
基本结构 Tomcat 的基本结构: Server └───Service ├───Connector (协议, 端口) └───Engine └───Host(虚拟主机 localhost) ├───Context1 (应用1, 可以设置虚拟路径, / 即 url 起始路径; 项目磁盘路径, 即 docBase ) │ │ index.html │ └───WEB-INF │ │ web…
除了直接通过浏览器从 Spring 官网下载框架代码以及通过 Idea 创建外,还可以通过 Linux 下的命令行 Web 客户端下载,优点是可以结合 Bash 命令或脚本实现一些自动化功能,此外也可以在 Idea 无法创建项目框架时作为一种替代方案。 curl -G https://start.spring.io/starter.tgz -d dependencies=web,lombok -d type=maven-project -d java-version=21 -d …
默认的 Spring 框架使用RequestMappingHandlerMapping进行请求路径映射,它会根据@RequestMapping注解进行路径映射,此外,Spring 框架还提供一些其它的路径映射方式。 BeanNameUrlHandlerMapping 使用 BeanNameUrlHandlerMapping 可以用 Bean 名称处理路径映射,在配置类中添加: /** * 处理器映射器,根据 bean 名称进行路径映射 * @return */ @Bean public BeanNameUrlHan…
ResponseBodyAdvice 对于控制器: @Controller @RequestMapping("/test") private static class TestController { @GetMapping("/hello") @ResponseBody public User hello() { return new User("Tom", 20); } } hello方法调用后的响应体: {"name":"Tom","age":20} 详细调用过程见源码。 …
Formatter Spring 用于类型转换的接口: Printer:将其它类型转换为字符串 Parser:将字符串转换为其它类型 Formatter:同时具备 Printer 和 Parser 的功能 Converter:将一种类型 S 转换为另一种类型 T(不限制类型的类型转换) Converters:将上述类型转换接口封装成标准的GenericConverter 接口,并组成集合使用 ConversionService:转换服务,通过 Converters 完成转换 PropertyEditor Sprin…
全局和局部 initBinder @InitBinder注解定义的方法不仅可以在 Controller 中添加,还可以在@ControllerAdvice定义的类中: @ControllerAdvice private static class MyControllerAdvice { @InitBinder public void globalInitBinder(WebDataBinder binder) { } } Controller 中的 InitBinder 方法仅对所在的 Contro…
在前文中介绍了用于处理控制器方法的参数解析器和返回值解析器,本篇文章展开讨论 Spring 框架提供的不同类型的参数解析器的用途。 添加一个控制器类: @Controller @RequestMapping("/test") private static class TestController { @GetMapping public String test(@RequestParam String name, @RequestParam Integer a…
Spring 中,用于加载和启动 Web Server 的容器类型是AnnotationConfigServletWebServerApplicationContext: AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(Config.class); new CountDownLatch(1).await(); 其配置类需要至少三个 B…
通过代理实现 AOP 下面演示怎么通过代理实现 AOP。 需要被 AOP 的类: interface Hello{ void sayHello(); void sayBye(); } static class Target implements Hello{ @Override public void sayHello() { System.out.println("Hello World"); } @Override public void sayBy…
魔芋红茶
加一点PHP,加一点Go,加一点Python......
COPYRIGHT © 2021 icexmoon.cn. ALL RIGHTS RESERVED.
本网站由提供CDN加速/云存储服务
Theme Kratos Made By Seaton Jiang