温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

springboot场景启动器怎么用

发布时间:2021-09-23 11:37:26 来源:亿速云 阅读:140 作者:小新 栏目:编程语言

这篇文章将为大家详细讲解有关springboot场景启动器怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

为什么springboot不需要我们去配置那么繁琐的东西?

我们直接看pom.xml

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>com.gong</groupId>  <artifactId>myspringboot</artifactId>  <version>1.0-SNAPSHOT</version>  <parent>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-parent</artifactId>    <version>1.5.9.RELEASE</version>  </parent>  <dependencies>    <!--引入springboot的web支持,帮你封装好了很多个依赖-->    <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-web</artifactId>    </dependency>  </dependencies>  <build>    <plugins>      <plugin>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-maven-plugin</artifactId>      </plugin>    </plugins>  </build></project>

首先看spring-boot-starter-parent,spring-boot-start就是场景启动器,这是所有项目的父项目,我们ctrl+鼠标左键点进去:

新文件的开头部分:

<parent>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-dependencies</artifactId>    <version>1.5.9.RELEASE</version>    <relativePath>../../spring-boot-dependencies</relativePath>  </parent>

它的父项目是spring-boot-dependencies,用于管理依赖包的版本号。也就是说spring-boot-start-parent是版本仲裁中心。

再来看spring-boot-starter-web,我们来查看其中有什么:

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <parent>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starters</artifactId>    <version>1.5.9.RELEASE</version>  </parent>  <artifactId>spring-boot-starter-web</artifactId>  <name>Spring Boot Web Starter</name>  <description>Starter for building web, including RESTful, applications using Spring    MVC. Uses Tomcat as the default embedded container</description>  <url>http://projects.spring.io/spring-boot/</url>  <organization>    <name>Pivotal Software, Inc.</name>    <url>http://www.spring.io</url>  </organization>  <properties>    <main.basedir>${basedir}/../..</main.basedir>  </properties>  <dependencies>    <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter</artifactId>    </dependency>    <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-tomcat</artifactId>    </dependency>    <dependency>      <groupId>org.hibernate</groupId>      <artifactId>hibernate-validator</artifactId>    </dependency>    <dependency>      <groupId>com.fasterxml.jackson.core</groupId>      <artifactId>jackson-databind</artifactId>    </dependency>    <dependency>      <groupId>org.springframework</groupId>      <artifactId>spring-web</artifactId>    </dependency>    <dependency>      <groupId>org.springframework</groupId>      <artifactId>spring-webmvc</artifactId>    </dependency>  </dependencies></project>

这里面才是帮我们导入了真正所需的依赖包。

springboot还有许多场景启动器,例如AOP、邮件开发等等。我们只需要在项目里面引用这些starter,这些场景的相关依赖包就会自动导入出来。

关于“springboot场景启动器怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI