文章目录
- SpringBoot
-
- 什么是SpringBoot ?(Spring的子项目)
- Springboot的启动流程(main方法的入口)
- SpringBoot常用注解
- Spring Boot Starter是什么?如何自定义Spring Boot Starter?
- 读取配置文件与配置属性类
- 什么是javaConfig(利用java配置)
- 什么是 Spring Profiles?
- spring-boot-starter-parent 有什么用 ?(硬背)
- Spring Boot 打成的 jar 和普通的 jar 有什么区别 ?
- SpringBoot中的WebMvcConfigurer
- 待解锁的springcloud联动问题(实习弃)
- Mybatis
- Mybatis-Plus学习
- 会话技术Session和cookie的应用
- 拦截器
- SpringSecurity
- 服务器异常处理(Advice)
- 日志记录 (log4j---AOP+注解版)
- Spring Quartz(任务定时调度框架)--帖子分数
- 前缀树(过滤敏感词)
- Mysql的声明式事务管理(@Transactional注解--AOP思想)
- Json和Ajax(了解)
SpringBoot
什么是SpringBoot ?(Spring的子项目)
Springboot的启动流程(main方法的入口)
一个Springboot项目的main方法的例子
@SpringBootApplication注解
@ComponentScan注解(对应扫描XML配置中的元素)
@SpringBootConfiguration (配置类就是对应Spring的xml 配置文件)
本质看看有没有注入第三方的bean,模式类上标注@Configuration注解+方法上表述@Bean注解
注意实例名是方法名,取名字的时候需要小心了
spring容器扫描注册bean的时候,会优先注册程序员自己写的bean,利用@ConditionOnMissingBean判断是不是需要注入最原始的Bean,如果发现容器中已经有程序员定义的bean了就不会注入原始的bean了
@EnableAutoConfiguration(自动装配的核心注解)
比如咱们进入那个AopAutoConfiguration自动配置类
SpringApplication.run的两件事
SpringApplication的实例化
getSpringFactoriesInstances(说明是从Spring.factories获取相应的spring容器的初始化器和程序监听器,这两个实际是这个类的成员变量,后续用在run方法上使用)
SpringApplication.run方法的执行
完成了实例化,下面开始调用run方法
// 运行run方法
public ConfigurableApplicationContext run(String... args) {
// 此类通常用于监控开发过程中的性能,而不是生产应用程序的一部分。
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = null;
Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();
// 设置java.awt.headless系统属性,默认为true
// Headless模式是系统的一种配置模式。在该模式下,系统缺少了显示设备、键盘或鼠标。
configureHeadlessProperty();
// KEY 1 - 获取SpringApplicationRunListeners(这个是事件监听器----从Spring.factories中获取)
SpringApplicationRunListeners listeners = getRunListeners(args);
// 通知监听者,开始启动
listeners.starting();
try {
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
args);
// KEY 2 - 根据SpringApplicationRunListeners以及参数来准备环境
ConfigurableEnvironment environment = prepareEnvironment(listeners,
applicationArguments);
configureIgnoreBeanInfo(environment);
// 准备Banner打印器 - 就是启动Spring Boot的时候打印在console上的ASCII艺术字体
Banner printedBanner = printBanner(environment);
// KEY 3 - 创建Spring上下文
context = createApplicationContext();
// 注册异常分析器
analyzers = new FailureAnalyzers(context);
// KEY 4 - Spring上下文前置处理
prepareContext(context, environment, listeners, applicationArguments,
printedBanner);
// KEY 5 - Spring上下文刷新
refreshContext(context);
// KEY 6 - Spring上下文后置处理
afterRefresh(context, applicationArguments);
// 发出结束执行的事件
listeners.finished(context, null);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass)
.logStarted(getApplicationLog(), stopWatch);
}
return context;
}
catch (Throwable ex) {
handleRunFailure(context, listeners, exceptionReporters, ex);
throw new IllegalStateException(ex);
}
}
顺序问题
SpringBoot常用注解
Spring Boot Starter是什么?如何自定义Spring Boot Starter?
是什么
怎么自定义((我们的功能类+)配置属性类+自动配置类+spring.factories)
配置属性类的作用(默认初始化的值+使用yaml配置文件“批量注入”类的属性值)
读取配置文件与配置属性类
添加传送门:@value(${配置文件的key})注解和@ConfigurationProperties 自定义属性类
@value注解方式:
自定义属性配置类方式:
首先定义一个属性类:做好在配置文件中的前缀设置
相应的配置类注册这个属性类的bean并使用使用这个配置好的属性bean来完成自己的属性填充
什么是javaConfig(利用java配置)
原来是xml文件+java来配置bean,现在是注解+java来配置bean(即纯java的方式)
什么是 Spring Profiles?
spring-boot-starter-parent 有什么用 ?(硬背)
Spring Boot 打成的 jar 和普通的 jar 有什么区别 ?
SpringBoot中的WebMvcConfigurer
你项目的应用有哪些?
1.登陆拦截器(addInterceptors:拦截器)
2.跳转页面(addViewControllers:页面跳转)
3.跨域配置( addCorsMappings:跨域)–鸡肋(适用于只有这一个拦截器的情况)
使用过滤器进行跨域配置,filter在servlet的外面
待解锁的springcloud联动问题(实习弃)
bootstrap(引导)的配置文件的作用
我们将多个的yaml文件配置在远程的服务配置中心nacos中,用于从远程中获取需要到的配置文件的相关信息
加载远程配置文件:
namespace+group+dataID(服务配置中心----多环境的切换)
Mybatis
什么是mybatis
JDBC的不足之处,Mybatis的改进方法
Mybatis的优缺点
Springboot中mybatis的配置
mybatis的工作原理
mapperstatement就是mapper.xml对应一个查询语句的标签对象,statementId就是namespace+方法名唯一映射形成的一个唯一的映射的对象
mapper.xml加载解析与注册mapper对应的代理类
SqlSessionFactoryBuilder.mapperElement() & 解析SQL语句(小腹哥的简易版本)
private Map<String, XNode> mapperElement(List<Element> list) {
Map<String, XNode> map = new HashMap<>();
Element element = list.get(0);
List content = element.content();
for (Object o : content) {
Element e = (Element) o;
String resource = e.attributeValue("resource");
try {
Reader reader = Resources.getResourceAsReader(resource);
SAXReader saxReader