当前位置:   article > 正文

SpringBoot框架介绍及使用_spring boot默认配置了哪些框架的使用方式

spring boot默认配置了哪些框架的使用方式

1. 概述

1.1 SpringBoot 简介

简化Spring应用开发的一个框架;
整个Spring技术栈的一个大整合;
J2EE开发的一站式解决方案;

1.2 微服务

微服务:架构风格(服务微化)
一个应用应该是一组小型服务;可以通过HTTP的方式进行互通;
单体应用:ALL IN ONE
微服务:每一个功能元素最终都是一个可独立替换和独立升级的软件单元;

1.3 SpringBoot自动配置原理

SpringBoot自动配置原理

2. 配置文件值注入

只有这个组件是容器中的组件,才能使用容器提供的@ConfigurationProperties功能;

@PropertySource(value = {"classpath:person.properties"})
@Component
@ConfigurationProperties(prefix = "person")
  • 1
  • 2
  • 3

@Value获取值和@ConfigurationProperties获取值比较:
在这里插入图片描述

3. 注册Servlet三大组件【Servlet、Filter、Listener】

由于SpringBoot默认是以jar包的方式启动嵌入式的Servlet容器来启动SpringBoot的web应用,没有web.xml文件。

// 注册Servlet服务
@Bean
public ServletRegistrationBean myServlet(){
   ServletRegistrationBean registrationBean = new ServletRegistrationBean(new MyServlet(),"/myServlet");
   return registrationBean;
}

// 注册过滤器
@Bean
public FilterRegistrationBean myFilter(){
	FilterRegistrationBean registrationBean = new FilterRegistrationBean();
	registrationBean.setFilter(new MyFilter());
	registrationBean.setUrlPatterns(Arrays.asList("/hello","/myServlet"));
	return registrationBean;
}

// 注册监听器
@Bean
public ServletListenerRegistrationBean myListener(){
	ServletListenerRegistrationBean<MyListener> registrationBean = new ServletListenerRegistrationBean<>(new MyListener());
	return registrationBean;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

4. SpringBoot 整合第三方插件

https://gitee.com/laocou/SpringBoot.git
关于SpringBoot 整合第三方插件的使用,上述链接的gitee代码中有详细介绍。

5.总结

上面只简单列出的SpringBoot最重要的基本概念。强烈建议大家将代码下载到本地,链接如下:https://gitee.com/laocou/SpringBoot.git。从头到尾整体过几遍,形成一个完整的知识框架,链接中这些内容已经基本覆盖平时项目开发中所用的知识点。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/987990
推荐阅读
相关标签
  

闽ICP备14008679号