名词解释:
BOM(bill of materials):材料清单,用于解决jar包依赖的好方法。
Spring IO Platform
缘起:Spring起初只专注ioc和aop,现在已发展成一个庞大体系。比如security、mvc等。如此一来,不同模块或者与外部进行集成时,依赖处理就需要各自对应版本号。比如,较新spring与较老的quartz,它们集成就会遇到问题,给搭建和升级带来不便。因此Spring IO Platform应运而生,只要项目中引入了它,外部集成时依赖关系无需版本号。官网的原文如下:“when you do declare a dependency on something that's part of the Platform, you will now be able to omit the version number.”
举例如下:
1
|
< code class = "hljs xml has-numbering" style = "display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;" >< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependencies</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependency</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >groupId</ span >></ span >org.springframework< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >groupId</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependency</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependencies</ span >></ span ></ code >< ul class = "pre-numbering" style = "box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);" >< li style = "box-sizing: border-box; padding: 0px 5px;" >1</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >2</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >3</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >4</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >5</ li ></ ul >
|
Spring IO Platform只是一个pom文件,记录了spring与其他开源项目对应的版本。省去了版本号,也就省去了处理依赖时的问题,因为Spring IO Platform中有最优的版本配置。
Spring相关的BOM
当然SpringSource为了解决这些Jar冲突,推出了各种BOM,当然最著名的就是spring platform io bom,其中最核心的三个是:spring-framework-bom、spring-boot-dependencies、platform-bom。
对于Spring工程来说,直接在pom.xml文件中添加如下配置代码,即可免去管理版本冲突的难题。
1
|
< code class = "hljs xml has-numbering" style = "display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;" >< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependencyManagement</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependencies</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependency</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >groupId</ span >></ span >org.springframework< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >groupId</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >artifactId</ span >></ span >spring-framework-bom< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >artifactId</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >version</ span >></ span >4.2.0.RELEASE< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >version</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >type</ span >></ span >pom< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >type</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >scope</ span >></ span >import< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >scope</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependency</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependency</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >groupId</ span >></ span >org.springframework.boot< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >groupId</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >artifactId</ span >></ span >spring-boot-dependencies< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >artifactId</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >version</ span >></ span >1.3.0.M2< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >version</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >type</ span >></ span >pom< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >type</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >scope</ span >></ span >import< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >scope</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependency</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependency</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >groupId</ span >></ span >io.spring.platform< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >groupId</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >artifactId</ span >></ span >platform-bom< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >artifactId</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >version</ span >></ span >1.1.3.RELEASE< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >version</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >type</ span >></ span >pom< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >type</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ><< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >scope</ span >></ span >import< span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >scope</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependency</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependencies</ span >></ span > < span class = "hljs-tag" style = "color: rgb(0, 102, 102); box-sizing: border-box;" ></< span class = "hljs-title" style = "box-sizing: border-box; color: rgb(0, 0, 136);" >dependencyManagement</ span >></ span ></ code >< ul class = "pre-numbering" style = "box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);" >< li style = "box-sizing: border-box; padding: 0px 5px;" >1</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >2</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >3</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >4</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >5</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >6</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >7</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >8</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >9</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >10</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >11</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >12</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >13</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >14</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >15</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >16</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >17</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >18</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >19</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >20</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >21</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >22</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >23</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >24</ li >< li style = "box-sizing: border-box; padding: 0px 5px;" >25</ li ></ ul >
|
参考文章
Introduction to spring io platform
总结
以上就是本文关于浅谈Spring解决jar包依赖的bom的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
原文链接:http://blog.csdn.net/u010535345/article/details/50698779