spring boot 第一个例子pom文件

Spring Boot启动Jetty教程
本文介绍如何在Spring Boot项目中删除自带的JUnit依赖,并添加父工程和Web依赖。通过配置,可以使用Jetty替代默认的Tomcat容器来启动应用。最后介绍了如何通过命令行启动Spring Boot应用。

1 删除自带的junit依赖


2 参考官网

http://projects.spring.io/spring-boot/,

添加父工程和web依赖等依赖
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.6.RELEASE</version>
</parent>

3 参考这篇博客
http://blog.youkuaiyun.com/catoop/article/details/50588851
添加jetty依赖,这样工程启动的时候,就会使用内嵌的jetty容器
否则选择默认的tomcat容器



4 cmd运行工程

cmd到工程路径下

mvn spring-boot:run

可以看到工程启动起来了,如果要终止,ctrl c

在 `pom.xml` 文件中引入 `spring-boot-dependencies` 的主要作用是利用 Spring Boot 提供的依赖管理机制,而不必继承 `spring-boot-starter-parent`。这种方式允许项目通过 `import` 作用域将 Spring Boot 定义的依赖版本管理策略引入到自己的项目中,从而确保所有与 Spring Boot 相关的依赖项能够使用一致且经过测试的版本。 具体来说,`spring-boot-dependencies` 是一个 POM 类型的 Maven 模块,它定义了多个与 Spring Boot 及其生态系统相关的依赖项的版本号和默认配置[^2]。这种集中式的依赖管理方式使得开发者可以避免手动指定各个库的版本,减少了版本冲突的可能性,并简化了依赖管理。 以下是一个典型的引入 `spring-boot-dependencies` 的方式: ```xml <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` 通过上述配置,项目可以直接使用 Spring Boot 提供的依赖管理功能[^2],例如引入特定的 Starter 模块而无需显式指定版本号,如下所示: ```xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> ``` 在这个例子中,`spring-boot-starter-web` 的版本由 `spring-boot-dependencies` 中的依赖管理所控制[^3]。 此外,`spring-boot-dependencies` 还支持自定义覆盖某些依赖的版本,以满足特定需求。例如,可以通过 `<properties>` 元素来定义自定义属性,从而修改第三方依赖的版本[^1]: ```xml <properties> <xml-apis.version>1.4.01</xml-apis.version> </properties> ``` 然后在依赖声明中引用该属性: ```xml <dependency> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> <version>${xml-apis.version}</version> </dependency> ``` 综上所述,`spring-boot-dependencies` 在 `pom.xml` 中的作用是提供一种灵活、可扩展的方式来管理项目的依赖版本,同时保持与 Spring Boot 生态系统的兼容性[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值