景区网站建设的意义,女生学计算机应用技术可以做什么,搜索引擎优化的核心及内容,sem推广什么意思前些天发现了一个巨牛的人工智能学习网站#xff0c;通俗易懂#xff0c;风趣幽默#xff0c;忍不住分享一下给大家。点击跳转到教程。
在初学spring boot时#xff0c;官方示例中#xff0c;都是让我们继承一个spring的 spring-boot-starter-parent 这个parent#xff…前些天发现了一个巨牛的人工智能学习网站通俗易懂风趣幽默忍不住分享一下给大家。点击跳转到教程。
在初学spring boot时官方示例中都是让我们继承一个spring的 spring-boot-starter-parent 这个parent
parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion1.5.1.RELEASE/version
/parentdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency
/dependencies
但是一般情况下在我们自己的项目中会定义一下自己的 parent 项目这种情况下上面的这种做法就行不通了。那么该如何来做呢其实在spring的官网也给出了变通的方法的
在我们自己 parent 项目中加下下面的声明 dependencyManagementdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion1.5.1.RELEASE/versiontypepom/typescopeimport/scope/dependency/dependencies
/dependencyManagement
请注意它的 type 是 pomscope 是 import这种类型的 dependency 只能在 dependencyManagement 标签中声明。 然后把我们项目中的 子项目 中parent 的声明修改为我们自己项目的 parent 项目就可以了比如我的是 parentgroupIdorg.test/groupIdartifactIdspring/artifactIdversion0.1-SNAPSHOT/version/parent 有一点需要注意一下。 在 子项目 的 dependencies 中不需要(也不能)再次添加对 spring-boot-dependencies 的声明了否则 子项目 将无法编译通过。 即在 子项目 中下面的配置是多余的
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactId
/dependency
为什么会这个样子呢 因为 spring-boot-dependencies 根本就没有对应的jar包它只是一个 pom 配置可以去 maven仓库 看一下。 它里面定义了 非常多 的依赖声明。
所以有了它之后我们在 子项目 中使用到的相关依赖就不需要声明version了如 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency
/dependencies
如spring-boot-starter-web 和 spring-boot-starter-test 在 spring-boot-dependencies 中的声明分别为 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdversion1.5.1.RELEASE/version
/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdversion1.5.1.RELEASE/versionexclusionsexclusiongroupIdcommons-logging/groupIdartifactIdcommons-logging/artifactId/exclusion/exclusions
/dependency 参考文档 - spring 官方文档