一、微服务相关概念
RPC
- 语言相关
JAVA: RMI
NET:COM+
- 语言无关
- SOA
web services
soap(传输介质协议)
HTTP、SMTP
2. 微服务 (MSA)
REST (Representational state transfer 表现层状态转换)
html,json,xml
HTTP(通讯协议)
二、SpringApplication
@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 {
...}
@SpringBootConfiguration 等价于 @Configuration
2、
ClassPathXmlApplicationContext xml文件驱动
AnnotationConfigApplicationContext 注解驱动
三、
个人觉得 spring boot的 自动装载功能,(spring.factory 扩展),可以融合了各个中间件;
1、类的自动装载方式AutoConfiguration
1.1 @EnableAutoConfiguration 自动 装配;
条件化或者动态加载如何做?
@Import(AutoConfigurationImportSelector) 可以导入其他jar中的class,托管给spring;支持动态扩展点spring.factories;
org.springframework.boot.autoconfigure.EnableAutoConfiguration=(com.example.demo.util.TimeUtil 或者对应的 @Configuration 配置类)
@AutoConfigurationPackage
@Import(AutoConfigurationPackages.Registrar.class)
关联的另外2个加载bean的方式,
1.2 @Configuration
1.3 @ComponentScan 默认加载该类所在路径下的目录和子目录,含有@Component @Service @Conntroller的注解的类托管给spring;
2、starter
3、Actuator 监控,健康检查
基于 HealthIndicator 接口扩展; 另外通过java MBeanServer 发布jmx节点cpu 内存 磁盘等信息,然后通过jconsole监控或者远程;
4、SpringBoot CLI
5、组件演化路径;
springboot上下文对象:AnnotationConfigServletWebServerApplicationContext
spring 容器启动:SpringApplication.refresh》AbstractApplicationContext.refresh
servlet容器启动:
AbstractApplicationContext.onRefresh() 》ServletWebServerApplicationContext.onRefresh》 ServletWebServerFactory getWebServerFactory()》TomcatServletWebServerFactory实例化》 WebServer getWebServer
springboot自动配置:
理念:约定大于配置;
约定了项目需要有哪些功能?
比如事务,配置文件加载与解析,aop,数据源,springmvc,缓存
SPI在springboot里面,就是去加载Meta-Inf下面的spring.factories文件的过程;
SpringFactoriesLoader.loadFactories 加载的类的实例一开始没有加入到spring容器; 如果需要交给spring容器,需要实现ImportSelector接口;
springboot2.7.5版本后,自动装配的是META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports下的文件;