Springcloud技术⽂档汇总(收集)
好的⽂章进⾏收集整理:
1.SpringApplication.run做了哪些事
2.SpringBoot @ConditionalOnBean、@ConditionalOnMissingBean
@ConditionalOnBean(Abc.class) Abc.class  已注⼊的Bean存在时处理
@ConditionalOnMissingBean(Abc.class)
@Bean
@ConditionalOnMissingBean
public NacosDiscoveryProperties nacosProperties() {
return new NacosDiscoveryProperties();
springmvc常用标签}
NacosDiscoveryProperties不存在时,进⾏初始化NacosDiscoveryProperties
@ConditionalOnProperty是指在l⾥配置的属性是否为true,其他的⼏个都是对class的判断。
3.Java中Class标签@PostConstruct和@PreDestroy,表⽰执⾏顺序,服务器仅加载⼀次
4.Spring cloud ⽹络配置相关,InetUtils、InetUtilsProperties和UtilAutoConfiguration提供了⽹络配置相关的功能。
Spring Cloud Netflix Eureka: 多⽹卡环境下Eureka服务注册IP选择问题
Spring Cloud Eureka 多⽹卡配置最终版
5.@CallerSensitive
6.EndPoint  主要⽤于暴漏SpringMvc内部运⾏的信息
Spring boot actuator监控端点集成,可以集成监控+数据暴漏+grafana图表软件,进⾏图形化展⽰
Endpoint也是通过spring.factories实现扩展功能,注⼊了对应的Bean来实现应⽤监控的功能
7.@Bean 注册对象时,⽅法参数是取Spring 容器中的具体声明类的注册Bean。如果声明类注册的对象有多个,则需要参数名⼀致,否则会报不确定选择哪个Bean。
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosAutoServiceRegistration nacosAutoServiceRegistration(
NacosServiceRegistry registry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
NacosRegistration registration) {
return new NacosAutoServiceRegistration(registry,
autoServiceRegistrationProperties, registration);
}
8.Spring autoConfigure  通过标签进⾏⾃动化配置,带条件的初始化,以及配置先后顺序,具体Bean没有了后进⾏⾃动再注册(防⽌对象的销毁,跟对象的初始化进⾏处理)
@Configuration
@EnableConfigurationProperties
@ConditionalOnNacosDiscoveryEnabled
@ConditionalOnProperty(value = "spring.cloud.abled", matchIfMissing = true)
@AutoConfigureAfter({ AutoServiceRegistrationConfiguration.class,
AutoServiceRegistrationAutoConfiguration.class })
public class NacosDiscoveryAutoConfiguration {
@Bean
public NacosServiceRegistry nacosServiceRegistry(
NacosDiscoveryProperties nacosDiscoveryProperties) {
return new NacosServiceRegistry(nacosDiscoveryProperties);
}
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosRegistration nacosRegistration(
NacosDiscoveryProperties nacosDiscoveryProperties,
ApplicationContext context) {
return new NacosRegistration(nacosDiscoveryProperties, context);
}
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosAutoServiceRegistration nacosAutoServiceRegistration(
NacosServiceRegistry registry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
NacosRegistration registration) {
return new NacosAutoServiceRegistration(registry,
autoServiceRegistrationProperties, registration);
}
}
9.SpringBoot使⽤ApplicationEvent&Listener完成业务解耦
10.Spring框架开发之SmartLifecycle接⼝
Spring加载和初始化所有bean后,接着执⾏⼀些任务或者启动需要的异步服务,当Spring容器加载所有bean并完成初始化之后,会接着回调实现该接⼝的类中对应的⽅法(start()⽅法)。
11.nacos discovery  流程原理
12.nacos 源码
13.Spring boot 配置资源类 PropertySourceLocator  远程config读取主要类
例如nacos的配置中⼼:
@Order(0)
public class NacosPropertySourceLocator implements PropertySourceLocator
14.Spring boot  FailureAnalyzer  ⼀种很好的⽅式在启动时拦截异常并将其转换为易读的消息,并将其包含在FailureAnalysis中。
public class NacosConnectionFailureAnalyzer
extends AbstractFailureAnalyzer<NacosConnectionFailureException> {
@Override
protected FailureAnalysis analyze(Throwable rootFailure,
NacosConnectionFailureException cause) {
return new FailureAnalysis("Application failed to connect to Nacos server",
"check your nacos server config", cause);
}
}
同时META-INF/spring.factories中添加
org.springframework.boot.diagnostics.FailureAnalyzer=\
org.springframework.cloud.alibaba.nacos.diagnostics.analyzer.NacosConnectionFailureAnalyzer 因为SpringApplication.run执⾏时初始化了FailureAnalyzers
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
args);
ConfigurableEnvironment environment = prepareEnvironment(listeners,
applicationArguments);
Banner printedBanner = printBanner(environment);
context = createApplicationContext();
analyzers = new FailureAnalyzers(context);
prepareContext(context, environment, listeners, applicationArguments,
printedBanner);
refreshContext(context);
afterRefresh(context, applicationArguments);
listeners.finished(context, null);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass)
.logStarted(getApplicationLog(), stopWatch);
}
return context;
15.AbstractHealthIndicator

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。