加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码门户网 (https://www.92codes.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 建站资源 > 优化 > 正文

Web框架的前生今世--从Servlet到Spring mvc到Spring boot

发布时间:2019-08-15 20:33:05 所属栏目:优化 来源:架构师笔记
导读:副标题#e# 背景 上世纪90年代,随着Internet和浏览器的飞速发展,基于浏览器的B/S模式随之火爆发展起来。最初,用户使用浏览器向WEB服务器发送的请求都是请求静态的资源,比如html、css等。 但是可以想象:根据用户请求的不同动态的处理并返回资源是理所当

2.2 编码方式

  1. public class MyWebAppInitializer implements WebApplicationInitializer { 
  2.   
  3.  @Override 
  4.  public void onStartup(ServletContext container) { 
  5.  // Create the 'root' Spring application context 
  6.  AnnotationConfigWebApplicationContext rootContext = 
  7.  new AnnotationConfigWebApplicationContext(); 
  8.  rootContext.register(AppConfig.class); 
  9.   
  10.  // Manage the lifecycle of the root application context 
  11.  container.addListener(new ContextLoaderListener(rootContext)); 
  12.   
  13.  // Create the dispatcher servlet's Spring application context 
  14.  AnnotationConfigWebApplicationContext dispatcherContext = 
  15.  new AnnotationConfigWebApplicationContext(); 
  16.  dispatcherContext.register(DispatcherConfig.class); 
  17.   
  18.  // Register and map the dispatcher servlet 
  19.  ServletRegistration.Dynamic dispatcher = 
  20.  container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); 
  21.  dispatcher.setLoadOnStartup(1); 
  22.  dispatcher.addMapping("/"); 
  23.  } 
  24.   
  25.  } 

内部实现

web框架的前生今世--从servlet到spring mvc到spring boot

3.spring boot

继承了spring mvc的框架,实现SpringBootServletInitializer

  1. package com.mkyong; 
  2. import org.springframework.boot.SpringApplication; 
  3. import org.springframework.boot.autoconfigure.SpringBootApplication; 
  4. import org.springframework.boot.builder.SpringApplicationBuilder; 
  5. import org.springframework.boot.web.support.SpringBootServletInitializer; 
  6. @SpringBootApplication 
  7. public class SpringBootWebApplication extends SpringBootServletInitializer { 
  8.  @Override 
  9.  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
  10.  return application.sources(SpringBootWebApplication.class); 
  11.  } 
  12.  public static void main(String[] args) throws Exception { 
  13.  SpringApplication.run(SpringBootWebApplication.class, args); 
  14.  } 

(编辑:源码门户网)

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