自动点击器下载,搜索引擎优化方法总结,jquery电子商务网站模板,贵阳白云网站建设在创建spring boot工程时#xff0c;spring-boot-starter-parent 和 spring-boot-dependencies是二选一的关系#xff0c;在pom中引入其中一个就可以了。
那么什么时候用spring-boot-starter-parent 和 spring-boot-dependencies呢#xff1f;从字面名称上看#xff0c;如…在创建spring boot工程时spring-boot-starter-parent 和 spring-boot-dependencies是二选一的关系在pom中引入其中一个就可以了。
那么什么时候用spring-boot-starter-parent 和 spring-boot-dependencies呢从字面名称上看如果我们要通过继承的方式引入springboot框架那么我们使用spring-boot-starter-parent 如果想通过依赖的方式引入springboot框架则我们使用spring-boot-dependencies。
下面给出我们常见的作法
spring-boot-starter-parent方式
我们需要在 parent 标签里引入spring-boot-starter-parent然后在dependencies标签里选择需要的具体依赖
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdboot-test/artifactIdversion1.0-SNAPSHOT/versionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.3.12.RELEASE/version/parentpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency/dependencies
/projectspring-boot-dependencies
我们需要在 dependencyManagement 标签里引入spring-boot-dependencies然后在dependencies标签里选择需要的具体依赖如下
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdboot-test/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency/dependenciesdependencyManagementdependencies!-- SpringBoot的依赖配置 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion2.3.12.RELEASE/versiontypepom/typescopeimport/scopeoptionaltrue/optional/dependency/dependencies/dependencyManagement
/project以上是我们常规的方法其实我试了下把 spring-boot-dependencies 作为parent方式即第一种方式项目也是可以启动成功的
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdboot-test/artifactIdversion1.0-SNAPSHOT/versionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion2.3.12.RELEASE/version/parentpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency/dependencies
/project这种方式不是推荐的方式因为springboot框架已经很贴心的给我们区分了两个概念 如果需要通过parent方式的话就是用spring-boot-starter-parent如果需要通过依赖的方式引入则使用spring-boot-dependencies
两者关系
我们点开spring-boot-starter-parent的pom内容如下
project xmlnshttp://maven.apache.org/POM/4.0.0 xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancemodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion2.3.12.RELEASE/version/parentartifactIdspring-boot-starter-parent/artifactIdpackagingpom/packagingnamespring-boot-starter-parent/namedescriptionParent pom providing dependency and plugin management for applications built with Maven/descriptionpropertiesjava.version1.8/java.versionresource.delimiter/resource.delimitermaven.compiler.source${java.version}/maven.compiler.sourcemaven.compiler.target${java.version}/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncoding/properties.../project很清晰的看到spring-boot-starter-parent是以spring-boot-dependencies为parent的只是加了一些maven build的插件而已所以两者内容虽然不能说很相似但可以说是完全一样。
按照潜规则想用继承方式我们就用spring-boot-starter-parent如果想通过依赖方式引入的话就用spring-boot-dependencies
spring-boot-dependencies依赖原理
点开 spring-boot-dependencies里面大部分是各种starter即各种独立功能自动装配的依赖 大家看下这个图就明白了 1、spring-boot-dependencies通过dependencyManagement管理各种starter 2、spring-boot-starter-parent通过parent依赖引入spring-boot-dependencies
starter命名规则可以看我另一篇文章https://blog.csdn.net/Aqu415/article/details/115875840
over~~