加入收藏 | 设为首页 | 会员中心 | 我要投稿 河北网 (https://www.hebeiwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 移动互联 > 正文

Spring和SpringBoot比较,解惑区别

发布时间:2019-04-04 22:09:01 所属栏目:移动互联 来源:SanLi
导读:1、概述: 对付 Spring 和 SpringBoot 到底有什么区别,我听到了许多谜底,刚开始迈入进修 SpringBoot 的我其时也是一头雾水,跟着履历的蕴蓄、我逐步领略了这两个框架到底有什么区别,我信托对付用了 SpringBoot 好久的开拓职员来说,有绝大部门还不是很
副问题[/!--empirenews.page--]

 Spring和SpringBoot较量,解惑区别

1、概述:

对付SpringSpringBoot到底有什么区别,我听到了许多谜底,刚开始迈入进修SpringBoot的我其时也是一头雾水,跟着履历的蕴蓄、我逐步领略了这两个框架到底有什么区别,我信托对付用了SpringBoot好久的开拓职员来说,有绝大部门还不是很领略SpringBoot到底和Spring有什么区别,看完文章中的较量,或者你有了差异的谜底和观点!

2、什么是Spring呢?

先来聊一聊Spring作为Java开拓职员,各人都Spring可不生疏,简而言之,Spring框架为开拓Java应用措施提供了全面的基本架构支持。它包括一些很好的成果,如依靠注入和开箱即用的模块,如:
       Spring JDBC 、Spring MVC 、Spring Security、 Spring AOP 、Spring ORM 、Spring Test
       这些模块各人应该都用过吧,这些模块收缩应用措施的开拓时刻,进步了应用开拓的服从
       譬喻,在Java Web开拓的早期阶段,我们必要编写大量的代码来将记录插入到数据源中。可是通过行使Spring JDBC模块的JDBCTemplate,我们可以将这操纵简化为只需设置几行代码。

3、什么是Spring Boot呢?

Spring Boot根基上是Spring框架的扩展,它消除了配置Spring应用措施所需的XML设置,为更快,更高效的开产生态体系铺平了阶梯。

以下是Spring Boot中的一些特点:

1:建设独立的spring应用。
 2:嵌入Tomcat, Jetty Undertow 并且不必要陈设他们。
 3:提供的“starters” poms来简化Maven设置
 4:尽也许自动设置spring应用。
 5:提供出产指标,结实搜查和外部化设置
 6:绝对没有代码天生和XML设置要求

4、让我们慢慢认识这两个框架

4.1、 Maven依靠

起首,让我们看一下行使Spring建设Web应用措施所需的最小依靠项

  1. <dependency> 
  2.     <groupId>org.springframework</groupId> 
  3.     <artifactId>spring-web</artifactId> 
  4.     <version>5.1.0.RELEASE</version> 
  5. </dependency> 
  6. <dependency> 
  7.     <groupId>org.springframework</groupId> 
  8.     <artifactId>spring-webmvc</artifactId> 
  9.     <version>5.1.0.RELEASE</version> 
  10. </dependency> 

与Spring差异,Spring Boot只必要一个依靠项来启动和运行Web应用措施:

  1. <dependency> 
  2.     <groupId>org.springframework.boot</groupId> 
  3.     <artifactId>spring-boot-starter-web</artifactId> 
  4.     <version>2.0.6.RELEASE</version> 
  5. </dependency> 

在举办构建时代,全部其他依靠项将自动添加到项目中。

另一个很好的例子就是测试库。我们凡是行使Spring TestJUnitHamcrestMockito库。在Spring项目中,我们应该将全部这些库添加为依靠项。可是在Spring Boot中,我们只必要添加spring-boot-starter-test依靠项来自动包括这些库。

Spring Boot为差异的Spring模块提供了很多依靠项。一些最常用的是:

spring-boot-starter-data-jpa
spring-boot-starter-security
spring-boot-starter-test
spring-boot-starter-web
spring-boot-starter-thymeleaf

有关starter的完备列表,请查察Spring文档。

4.2、MVC设置

让我们来看一下SpringSpring Boot建设JSP Web应用措施所需的设置。

Spring必要界说调治措施servlet,映射和其他支持设置。我们可以行使 web.xml 文件或Initializer类来完成此操纵:

  1. public class MyWebAppInitializer implements WebApplicationInitializer { 
  2.    
  3.     @Override 
  4.     public void onStartup(ServletContext container) { 
  5.         AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); 
  6.         context.setConfigLocation("com.pingfangushi"); 
  7.           container.addListener(new ContextLoaderListener(context)); 
  8.           ServletRegistration.Dynamic dispatcher = container 
  9.           .addServlet("dispatcher", new DispatcherServlet(context)); 
  10.         dispatcher.setLoadOnStartup(1); 
  11.         dispatcher.addMapping("/"); 
  12.     } 

(编辑:河北网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读