1.为何要使用springboot
springboot的框架优势:如下摘自spring官网对springboot的介绍;https://spring.io/projects/spring-bootjava
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".web
We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.spring
使用Spring Boot能够很容易的建立独立的,基于生产级别的基于Spring的应用程序,能够直接运行它。 咱们能够很容易的使用它集成第三方的依赖,减小了没必要要的麻烦。大多数Spring Boot应用程序只须要不多的Spring配置。数据库
Features(特色)springboot
-
Create stand-alone Spring applications 建立独立的Spring应用程序服务器
-
Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files) 直接嵌入了Tomcat,Jetty或Undertow(无需部署WAR包了)app
-
Provide opinionated 'starter' dependencies to simplify your build configuration 提供了初始化的依赖,简化了配置框架
-
Automatically configure Spring and 3rd party libraries whenever possible 自动配置spring和第三方库maven
-
Provide production-ready features such as metrics, health checks and externalized configuration 提供生产环境的一些功能,例如指标,运行情况检查和外部配置ide
-
Absolutely no code generation and no requirement for XML configuration 彻底没有代码生成,也不须要XML配置
优势:
(如下为网友总结的,其实和官网所说的是同样的,只是更加容易理解):
- 使用Java或Groovy开发基于Spring的应用程序很是容易。
- 它减小了大量的开发时间并提升了生产力。
- 它避免了编写大量的样板代码,注释和XML配置。
- Spring Boot应用程序与其Spring生态系统(如Spring JDBC,Spring ORM,Spring Data,Spring Security等)集成很是容易。
- 它遵循“自用默认配置”方法,以减小开发工做量。
- 它提供嵌入式HTTP服务器,如Tomcat,Jetty等,以开发和测试Web应用程序很是容易。
- 它提供CLI(命令行界面)工具从命令提示符,很是容易和快速地开发和测试Spring Boot(Java或Groovy)应用程序。
- 它提供了许多插件来开发和测试Spring启动应用程序很是容易使用构建工具,如Maven和Gradle。
- 它提供了许多插件,以便与嵌入式和内存数据库工做很是容易。
缺点:
- 将现有或传统的Spring Framework项目转换为Spring Boot应用程序是一个很是困难和耗时的过程。它仅适用于全新Spring项目。
2.搭建springboot项目
1.file->new->project 选择maven建立项目,直接下一步
2.填写groupid、artifactid、version等信息,而后点击下一步
3.而后在建立的项目的pom中添加springboot的依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
4.使用spring官网建立springboot项目
填写本身建立项目的信息,而后点击generate进行生成,会生成一个demo.zip的包,解压后,使用idea导入便可
springboot下一章讲解启动类