SpringBoot学习之始
-
什么是SpringBoot?
-
它的运行原理是什么?
-
它的配置文件如何编写。
-
如何使用它开发web项目。
-
它是如何集成数据库的,druid
-
权限管理如何做
-
swagger:接口文档
-
任务调度
-
分布式开发:Dubbo+Zookeeper
一、SpringBoot是什么
它就是一个javaweb的开发框架,和SpringMVC类似。SpringBoot是基于Spring开发,SpringBoot本身并不提供Spring框架的核心特性以及扩展功能,只是用于快速、敏捷的开发新一代基于Spring的应用程序。它并不是用来代替spring 的,而是与Spring结合起来提升Spring开发者体验的工具。SpringBoot以约定大于配置的思想,帮我们提供了很多默认配置,我们只需要很少的Spring配置,就可以开发出来一个应用程序。它默认配置了很多框架的使用方式,集成第三方框架,几乎可以零配置的开箱即用。maven整合了所有的jar包,SpringBoot整合了所有的框架。
二、SpringBoot能干什么
对比其他javaweb框架的好处,官方说是简化开发,约定大于配置,you can "just run",能迅速的开发web应用,几行代码开发一个http接口。
-
为所有Spring开发者更快的入门
-
开箱即用,提供各种默认配置来简化项目配置
-
内嵌式容器简化web项目
-
没有冗余代码生成和xml配置的要求
三、SpringBoot怎么使用
1. 第一个SpringBoot程序
-
使用Spring Initializr创建一个SpringBoot程序
-
G com.lele
-
A hellofirst
-
默认的包中将hellofirst删掉,比较方便
-
-
选择web,添加spring web依赖,完成
-
默认创建了包com.lele.hellofirst,并在hellofirst包下创建了HellofirstApplication.class启动类。
-
在hellofirst包下新建一个包controller,与启动类同级,Springboot会扫描与启动类同级的包,而不会扫描同级的类
-
在controller包下新建一个类HelloController
-
第一个SpringBoot程序写好了,可以通过启动类启动程序。通过http://localhost:8080/hello访问。
2.更改Tomcat的端口号
server
3.更改banner
在resource下新建一个banner.txt,将自定义的图片,艺术字等放进去。
四、原理初探
自动配置:核心是pom
-
pom中有parent<artifactId>spring-boot-starter-parent</artifactId>,进去后还有parent<artifactId>spring-boot-dependencies</artifactId>,点击去后无parent了,有各种jar包
<properties>
<activemq.version>5.16.3</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
<appengine-sdk.version>1.9.92</appengine-sdk.version>
...
<wsdl4j.version>1.6.3</wsdl4j.version>
<xml-maven-plugin.version>1.0.2</xml-maven-plugin.version>
<xmlunit2.version>2.8.3</xmlunit2.version>
</properties>而在<artifactId>spring-boot-starter-parent</artifactId>中,有资源过滤自动配好了,插件也配置好了。
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/application*.yml</include>
<include>**/application*.yaml</include>
<include>**/application*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>**/application*.yml</exclude>
<exclude>**/application*.yaml</exclude>
<exclude>**/application*.properties</exclude>
</excludes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>${java.version}</jvmTarget>
<javaParameters>true</javaParameters>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>