[英]Better way of using spring boot starters
I found two way of adding dependencies for spring boot rest service application.我找到了两种为 spring boot rest 服务应用程序添加依赖项的方法。
Method 1 :方法一:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
Method 2:方法二:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Both method given above does the same job?上面给出的两种方法都做同样的工作? Any difference in performance?
性能上有什么区别吗?
Thanks in advance提前致谢
The difference between these methods is that spring-boot-starter-web
contains more dependencies than just spring-boot-starter
and spring-web
.这些方法之间的区别在于
spring-boot-starter-web
包含更多的依赖项,而不仅仅是spring-boot-starter
和spring-web
。
For the version 1.5.8.RELEASE it will be:对于 1.5.8.RELEASE 版本,它将是:
All other stuff depends on your requirements.所有其他的东西取决于你的要求。 For instance, if you're developing commercial product you must check all included transitive dependencies for their licenses.
例如,如果您正在开发商业产品,您必须检查其许可证的所有包含的传递依赖项。
The general advice is to use only features you need.一般建议是仅使用您需要的功能。 Don't forget that you still can depend on top level artifact excluding not required parts using Maven feature.
不要忘记,您仍然可以依赖顶级工件,不包括使用 Maven 功能的不需要的部分。
At for the performance boost, basically it should not be that much.在性能提升方面,基本上应该不会那么多。 The difference is only if the Spring (with top-level artifact dependency) will load and auto configure some features which are not practically used in your code (during the classpath scanning).
区别仅在于 Spring(具有顶级工件依赖项)将加载并自动配置一些在您的代码中实际上未使用的功能(在类路径扫描期间)。 The startup time could be slightly increased by the same reason.
出于同样的原因,启动时间可能会略有增加。
Hope it helps!希望能帮助到你!
Obviously second approach is better ie using springboot starter pom.显然第二种方法更好,即使用 springboot starter pom。
Reasons I say that for are as follows:-我这么说的原因如下:-
It allows zero configuration
or auto configuration
ie most of the web related settings would be given to you by default.它允许
zero configuration
或auto configuration
即默认情况下将向您提供大多数与 Web 相关的设置。 eg by default tomcat server would be integrated, springboot dependencies would be added for you, automatic registration of converter and other web related dependencies etc. See this link.例如默认情况下将集成 tomcat 服务器,将为您添加 springboot 依赖项,自动注册转换器和其他与 Web 相关的依赖项等。请参阅此链接。
You could take advantage of easy override ie if tomorrow you want to use jetty in place of tomcat just add the jetty dependency and it's configurations and now you could use jetty.您可以利用简单的覆盖,即如果明天您想使用 jetty 代替 tomcat,只需添加 jetty 依赖项及其配置,现在您可以使用 jetty。
Your pom.xml
would be neater and more readable as less no.你的
pom.xml
会更整洁,更易读,因为更少。 of dependencies are put inside it and picked from starter poms.依赖项被放入其中并从 starter poms 中挑选。
Easy compatibility management.轻松的兼容性管理。 By default spring-boot picks up the version of
starter parent
.默认情况下,spring-boot 选择
starter parent
的版本。 Hence, you could rest assured that all compatible dependencies would be downloaded as part of mvn dependencies and if you specifically want to upgrade any of those you could.因此,您可以放心,所有兼容的依赖项都将作为 mvn 依赖项的一部分下载,如果您特别想升级其中任何一个,则可以。 But this gives advantage of upgrading to compatible dependencies by just changing the version of springboot starter parent(Note: You could use dependency management as well in place of starter parent pom. See this link).
但这可以通过更改 springboot starter parent 的版本来升级到兼容的依赖项(注意:您也可以使用依赖项管理来代替 starter parent pom。请参阅此链接)。
Performance wise there would be a trade-off as springboot by default downloads more dependencies than minimum required initially.在性能方面会有一个折衷,因为 springboot 默认下载比最初所需的最小值更多的依赖项。 But over the time as application starts becoming mature most of these dependencies are used anyways.
但是随着应用程序开始变得成熟,大多数这些依赖项无论如何都会被使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.