NoteDeep

spring 框架核心:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-introduction

spring 配置项 https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html

starters
https://docs.spring.io/spring-boot/docs/2.5.0/reference/htmlsingle/#using.build-systems.starters

grpc-server-spring-boot-starter

Spring Boot starter module for gRPC framework.spring boot
可以依赖它,来快速实现对 grpc 的支持 这个库依赖(引入)很多最基础的 grpc 和 protobuf 库,所以基本上确定了 grpc 和 protobuf 的版本

mybatis-spring-boot-starter

帮助你基于 spring boot 上构建 mybatis 应用

bean 的加载

@SpringBootApplication 包含了 @ComponentScan@ComponentScan
// Base packages to scan for annotated components.表示在 Base packages 中扫描带有 @component 注解的 bean,默认是当前包。
即默认会扫描 @SpringBootApplication 所在的包,把其中的 @component 定义的 bean 注册到容器中。
所以即使在另一个 gradle project 中定义了 @component,只要是在 @SpringBootApplication 在同一个包下,component 就能被自动加载


参考: https://www.liaoxuefeng.com/wiki/1252599548343744/1266263217140032

spring boot 如何注册 bean 的, java 的容器是如何初始化的

The IoC Container 是什么 ?

什么是容器?容器提供组件运行的环境,提供更底层的服务。例如,Servlet容器底层实现了TCP连接,解析HTTP协议等非常复杂的服务。
Spring的核心就是提供了一个IoC容器,它可以管理所有轻量级的JavaBean组件,提供的底层服务包括组件的生命周期管理、配置和组装服务等

IoC全称Inversion of Control,直译为控制反转。
控制权发生了反转,即从应用程序转移到了IoC容器,所有组件不再由应用程序自己创建和配置,而是由IoC容器负责。
应用程序只需要直接使用已经创建并且配置好的组件

通过注解 Spring 自动扫描 Bean,注解告诉 IoC 容器应该如何创建并组装Bean
@Autowired 把指定类型的 Bean 注入到指定的字段中。
@ComponentScan,它告诉容器,自动搜索当前类所在的包以及子包,把所有标注为@Component的Bean自动创建出来,并根据@Autowired进行装配。

Spring还可以根据@Conditional决定是否创建某个Bean。
https://www.liaoxuefeng.com/wiki/1252599548343744/1308043874664482

@Configuration 是什么
Indicates that a class declares one or more {@link Bean @Bean} methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime

spring 如何读取请求并转化为 protobuf 的?

配置 message-converters
https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-config-message-converters
spring 处理请求方法参数,参考:https://docs.spring.io/spring-framework/docs/current/reference/html/web.htmll#mvc-ann-arguments
校验:https://docs.oracle.com/javaee/7/tutorial/bean-validation001.htm
首先通过实现 HandlerMethodArgumentResolver,接管GET 和 DELETE 请求。然后在实现 ProtobufHttpMessageConverter,给对象里set 一些url上的参数。
spring-web 提供的 ProtobufHttpMessageConverter 是什么?
* An {@code HttpMessageConverter} that reads and writes * {@link com.google.protobuf.Message com.google.protobuf.Messages}
readInternal 把输入的 org.springframework.http.HttpInputMessage 转成需要的 com.google.protobuf.Message
spring 如何把 protobuf 输出为 json 的?
同样是依赖这个 ProtobufHttpMessageConverter

默认的 converts
getDefaultConverters,addDefaultHttpMessageConverters

spring 如何写测试用例

参考文档:
https://docs.spring.io/spring-framework/docs/current/reference/html/testing.html#testing-introduction
https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing
https://docs.spring.io/spring-security/site/docs/current/reference/html5/#test





评论列表

    spring 框架核心:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-introduction
    grpc-server-spring-boot-starter
    mybatis-spring-boot-starter
    bean 的加载
    spring 如何写测试用例