idea springboot整合jsp注意事项:创建的maven工程必须要war包,创建完成之前,add maven property Name:archetypeCatalog,value:internal
springboot2多数据源读取名称存在bug: url要换成jdbc-url
注解篇:@ConfigurationProperties(prefix = "spring.datasource.member")指定数据源
@Data,lombok插件class文件反编译后可以看到get,set方法
@MapperScan:作用:指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类
@RestController注解:相当于@Controller+@ResponseBody两个注解的结合,返回json数据不需要在方法前面加@ResponseBody注解了,但使用@RestController这个注解,就不能返回jsp,html页面,视图解析器无法解析jsp,html页面
@Controller 注解,在对应的方法上,视图解析器可以解析return 的jsp,html页面,并且跳转到相应页面,若返回json等内容到页面,则需要加@ResponseBody注解
@SpringBootApplication = (默认属性)@Configuration + @EnableAutoConfiguration + @ComponentScan。
@Configuration用于定义配置类,可替换xml配置文件 ,@Configuration配置spring并启动spring容器,@Configuration标注在类上,相当于把该类作为spring的xml配置文件中的<beans>
,作用为:配置spring容器(应用上下文)
@Bean标注在方法上(返回某个实例的方法),等价于spring的xml配置文件中的<bean>
,作用为:注册bean对象
@EnableAutoConfiguration:能够自动配置spring的上下文,试图猜测和配置你想要的bean类,通常会自动根据你的类路径和你的bean定义自动配置。
@ComponentScan:会自动扫描指定包下的全部标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Repository,@Controller。
@ControllerAdvice 异常的切面类,所有异常都会进这里来,捕获全局异常
SpringBoot为什么能够实现开发者快速的整合第三方框架:原理:Maven依赖的封装整合和starter
: <!--
spring-boot-starter-web(spring MVC),spring-boot-starter-freemarker(freemarker),spring-boot-starter-redis(redis),spring-boot-starter-amqp(mq)-->
完全去除XML配置,采用注解形式:原理:SpringBoot根据Spring体系原生的注解实现包装,SpringBoot设计理念,完全采用注解形式
SpringBootConfiguration-->点开后 可以看到引入了@Configuration注解,这样程序员就可以直接在方法上使用bean注解。
不需要外部容器,内嵌入服务器(Tomcat):原理:java语言创建tomcat服务器,然后将本地class文件交给tomcat加载
mvn clean install java -jar (jar名称)
Springboot启动流程:1.创建 new SpringApplication 2.调用run方法
springboot最大新特性:响应式编程(https://blog.csdn.net/mmx8112/article/details/85600037)
Springboot启动流程:核心分为两个步骤:
1.创建 new SpringApplication 对象 2.调用SpringApplication run方法 实现启动同时返回当前容器上下文
细流程
1.创建SpringApplication 对象Springboot容器初始化操作
2.获取当前应用启动类型 原理:判断当前classpath是否有加载我们的servlet类 返回servlet启动方式
3. WebApplicationType
NONE 不会嵌入我们的web服务器,最终通过外部tomcat服务器
SERVLET 需要使用SERVLET运行,基于web容器启动
REACTIVE 使用响应式启动(Spring5新特性)
4.setInitializers读取Springboot包下面的MATE-INF/srping.factories文件获取到对应的ApplicationContextInitializer装配到集合中(也包括springboot-autoconfigure包下面的MATE-INF/srping.factories文件获取到对应的 ApplicationListener 装配到集合中)
setListeners读取Springboot包下面的MATE-INF/srping.factories文件获取到对应的 ApplicationListener 装配到集合中
5.mainApplicationClass获取当前运行的主函数
6.调用SpringApplication run方法实现启动
7.StopWatch stopWatch = new StopWatch();记录springboot项目启动时间
8.SpringApplicationRunListeners listeners = getRunListeners(args); new SpringApplicationRunListeners 加载EventPublishingRunListener文件,EventPublishingRunListener负责将配置文件赋值到程序中
9. listeners.starting();循环调用监听starting方法
10.ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
一:listeners.environmentPrepared(environment);读取我们的配置文件到Springboot容器中
读取配置文件多种来源
classpath:/, classpath:/config/,file:./,file:./config/
classpath和file读取文件的区别:classpath读取编译后的文件内容,file读取编译前的配置文件。默认读取配置名称是application
读取多个配置
Application.yml
Application.xml
Application.Properties
Application.yaml
Application-dev-yml
11.Banner printedBanner = printBanner(environment);打印我们的springboot Banner
12.创建springboot上下文AnnotationConfigServletWebServerApplicationContext初始化对象
13.refreshContext(context);
14.开始创建tomcat容器
15.开始加载sringmvc
16.定义一个空的模板方法 afterRefresh 给其他子类重写
17.listeners.started(context);开始使用广播和回调机制通知监听器springboot容器已经启动成功
18.listeners.running(context);开始使用广播和回调机制通知监听器springboot容器已经启动成功 running
19.返回上下文context
Spring体系核心设计模式分析:
spring中有哪些启动方式?注解和xml
spring常用注解
springBean的生命周期,后置处理器
spring事务底层原理 为什么会失效的呢? Aop技术 不能try
SpringAop中五个通知如何形成调用关联 设计模式 责任链和递归模式
spring的循环依赖是如何解决的呢?解决循环依赖的底层原理是什么?三级缓存