我刚刚开始学习春天。在我的下一步,我想开发更大的网络应用程序。

现在我想知道我是否应该从Spring Boot或Spring MVC开始。我已经读了一些东西,但这是令人困惑的,因为两者看起来相似。

那么两者之间有什么不同呢?


当前回答

以下是区分Spring、Spring MVC和Spring Boot的一些要点:

春天:

Main Difference is "Test-ability". Spring come with the DI and IOC. Through which all hard-work done by system we don't need to do any kind of work(like, normally we define object of class manually but through Di we just annotate with @Service or @Component - matching class manage those). Through @Autowired annotation we easily mock() it at unit testing time. Duplication and Plumbing code. In JDBC we writing same code multiple time to perform any kind of database operation Spring solve that issue through Hibernate and ORM. Good Integration with other frameworks. Like Hibernate, ORM, Junit & Mockito.

Spring MVC

Spring MVC框架是Spring的一个模块,它为面向HTTP的web应用开发提供了便利。 Spring MVC在输入逻辑(控制器)、业务逻辑(模型)和UI逻辑(视图)上有明确的代码分离。 Spring MVC模式有助于开发灵活和松散耦合的web应用程序。 根据您的需要,提供各种硬编码方式来定制您的应用程序。

Spring Boot:

Create of Quick Application so that, instead of manage single big web application we divide them individually into different Microservices which have their own scope & capability. Auto Configuration using Web Jar : In normal Spring there is lot of configuration like DispatcherServlet, Component Scan, View Resolver, Web Jar, XMLs. (For example if I would like to configure datasource, Entity Manager Transaction Manager Factory). Configure automatically when it's not available using class-path. Comes with Default Spring Starters, which come with some default Spring configuration dependency (like Spring Core, Web-MVC, Jackson, Tomcat, Validation, Data Binding, Logging). Don't worry about versioning issue as well.

(演化类似:Spring -> Spring MVC -> Spring Boot,所以新版本兼容旧版功能。) 注:它不包含所有点。

其他回答

Spring MVC is a complete HTTP oriented MVC framework managed by the Spring Framework and based in Servlets. It would be equivalent to JSF in the JavaEE stack. The most popular elements in it are classes annotated with @Controller, where you implement methods you can access using different HTTP requests. It has an equivalent @RestController to implement REST-based APIs. Spring boot is a utility for setting up applications quickly, offering an out of the box configuration in order to build Spring-powered applications. As you may know, Spring integrates a wide range of different modules under its umbrella, as spring-core, spring-data, spring-web (which includes Spring MVC, by the way) and so on. With this tool you can tell Spring how many of them to use and you'll get a fast setup for them (you are allowed to change it by yourself later on).

因此,Spring MVC是一个用于web应用程序的框架,Spring Boot是一个基于Spring的生产就绪项目初始化器。您可能会发现访问Spring MVC标记wiki以及SO中的Spring Boot标记wiki很有用。

简单来说,它可以表述为:

Spring boot = Spring MVC +自动配置(不需要编写Spring .xml文件进行配置)+服务器(您可以有嵌入式Tomcat, Netty, Jetty服务器)。

Spring Boot是一个opiniated框架,因此它的构建考虑到了开发速度快,配置时间短,并且有很好的社区支持。

以下是区分Spring、Spring MVC和Spring Boot的一些要点:

春天:

Main Difference is "Test-ability". Spring come with the DI and IOC. Through which all hard-work done by system we don't need to do any kind of work(like, normally we define object of class manually but through Di we just annotate with @Service or @Component - matching class manage those). Through @Autowired annotation we easily mock() it at unit testing time. Duplication and Plumbing code. In JDBC we writing same code multiple time to perform any kind of database operation Spring solve that issue through Hibernate and ORM. Good Integration with other frameworks. Like Hibernate, ORM, Junit & Mockito.

Spring MVC

Spring MVC框架是Spring的一个模块,它为面向HTTP的web应用开发提供了便利。 Spring MVC在输入逻辑(控制器)、业务逻辑(模型)和UI逻辑(视图)上有明确的代码分离。 Spring MVC模式有助于开发灵活和松散耦合的web应用程序。 根据您的需要,提供各种硬编码方式来定制您的应用程序。

Spring Boot:

Create of Quick Application so that, instead of manage single big web application we divide them individually into different Microservices which have their own scope & capability. Auto Configuration using Web Jar : In normal Spring there is lot of configuration like DispatcherServlet, Component Scan, View Resolver, Web Jar, XMLs. (For example if I would like to configure datasource, Entity Manager Transaction Manager Factory). Configure automatically when it's not available using class-path. Comes with Default Spring Starters, which come with some default Spring configuration dependency (like Spring Core, Web-MVC, Jackson, Tomcat, Validation, Data Binding, Logging). Don't worry about versioning issue as well.

(演化类似:Spring -> Spring MVC -> Spring Boot,所以新版本兼容旧版功能。) 注:它不包含所有点。

Spring MVC是Spring框架的子项目,针对使用MVC(模型-视图-控制器)模式的应用程序的设计和开发。Spring MVC被设计成与Spring框架和大多数其他子项目完全、完整地集成。

Spring Engineering团队可以从这篇文章中很好地理解Spring Boot。它被认为是固执己见的,也就是说,它大力提倡某种快速开发风格,但它的设计足够好,可以容纳规则的例外。简而言之,它是一种优于配置方法的约定,它愿意理解您在必要时打破约定的需求。

使用spring引导,您将不需要构建配置。这将在您创建项目时自动完成。 如果你使用spring MVC,你需要自己构建配置。它更复杂,但也至关重要。