博客
关于我
SpringMVC零xml配置原理
阅读量:440 次
发布时间:2019-03-06

本文共 770 字,大约阅读时间需要 2 分钟。

Spring Boot实现零配置Spring MVC的原理主要包括以下几个方面:

  • 不使用web.xml

    • 实现WebApplicationInitializer接口:通过重写onStartup方法,初始化Spring容器并注册配置类。Spring Boot通过实现WebApplicationInitializer接口,自动配置Spring容器,避免了传统的web.xml配置。
    • AnnotationConfigWebApplicationContext:使用注解配置,注册配置类到Spring容器中,实现了无需xml文件的配置需求。
    • DispatcherServlet自动注册:通过手动创建并注册DispatcherServlet,处理请求,减少了对web.xml的依赖。
  • 动态加载配置类

    • SPI机制:Spring Boot利用SPI机制,自动发现实现了ServletContainerInitializer接口的类,动态加载配置类,减少了手动配置的工作量。
    • @HandlesTypes注解:配置需要处理的接口类型,Spring Boot自动扫描实现类并调用对应方法,实现了灵活的配置扩展。
  • 不使用spring-mvc.xml

    • 实现WebMvcConfigurer接口:通过注解配置视图解析器、消息转换器等,简化了传统xml配置的繁琐过程。
    • 覆盖默认配置:自定义配置类覆盖Spring默认的MVC配置,实现了高度的定制化。
  • 真正的零配置

    • 内嵌Tomcat:Spring Boot通过内嵌Tomcat避免了web.xml的使用,但需注意静态资源访问问题。
    • 程序入口启动:通过main方法启动内嵌服务器,实现了无需xml文件的项目启动。
  • Spring Boot的零配置机制通过注解和自动化配置,简化了开发流程,提升了效率和代码可维护性。

    转载地址:http://iclyz.baihongyu.com/

    你可能感兴趣的文章
    Oracle:ORA-00911: 无效字符
    查看>>
    Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
    查看>>
    TCP基本入门-简单认识一下什么是TCP
    查看>>
    tableviewcell 中使用autolayout自适应高度
    查看>>
    Orcale表被锁
    查看>>
    svn访问报错500
    查看>>
    Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
    查看>>
    org.apache.ibatis.exceptions.PersistenceException:
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    SQL-CLR 类型映射 (LINQ to SQL)
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
    查看>>
    org.tinygroup.serviceprocessor-服务处理器
    查看>>