当前位置: 首页 > news >正文

一个完整的企业网站平面设计广告公司

一个完整的企业网站,平面设计广告公司,服装网页设计图片,郑州建设网站前言 我们也知道springboot启用springmvc基本不用做什么配置可以很方便就使用了但是不了解原理,开发过程中遇到点问题估计就比较头疼,不管了解的深不深入,先巴拉一番再说… 下面我们先看看官网…我的版本是2.3.2版本,发现官网改动也比较大…不同版本自己巴拉下吧,结构虽然变化…前言 我们也知道springboot启用springmvc基本不用做什么配置可以很方便就使用了但是不了解原理,开发过程中遇到点问题估计就比较头疼,不管了解的深不深入,先巴拉一番再说… 下面我们先看看官网…我的版本是2.3.2版本,发现官网改动也比较大…不同版本自己巴拉下吧,结构虽然变化了,但是内容变的不是很多… 有变动的 都标有: covered later in this document springmvc 自动配置原理 官网上说明 自动配置在Spring的默认设置之上添加了以下功能 ContentNegotiatingViewResolver and BeanNameViewResolver 这2个bean 配置在WebMvcAutoConfiguration中 自动配置了ViewResolver视图解析器根据方法的返回值得到视图对象View视图对象决定如何渲染转发重定向ContentNegotiatingViewResolver组合所有的视图解析器的如何定制我们可以自己给容器中添加一个视图解析器自动的将其组合进来代码 SpringBootApplication public class ComWebApplication {public static void main(String[] args) {SpringApplication.run(ComWebApplication.class, args);}Beanpublic ViewResolver myViewReolver(){return new MyViewResolver();}public static class MyViewResolver implements ViewResolver{Overridepublic View resolveViewName(String viewName, Locale locale) throws Exception {return null;}}}Support for serving static resources, including support for WebJars (see below).静态资源文件夹路径,webjars 在静态资源映射规则中已经讲解自动注册了 of Converter , GenericConverter , Formatter beans. Converter转换器 public String hello(User user)类型转换使用Converter Formatter 格式化器 2017.12.17Date public void addFormatters(FormatterRegistry registry) {ApplicationConversionService.addBeans(registry, this.beanFactory);}自己添加的格式化器转换器我们只需要放在容器中即可 HttpMessageConverterSpringMVC用来转换Http请求和响应的User—Json -HttpMessageConverters 是从容器中确定获取所有的HttpMessageConverter 自己给容器中添加HttpMessageConverter只需要将自己的组件注册容器中Bean,Component Automatic registration of MessageCodesResolver (see below).定义错误代码生成规则 Static index.html support. 静态首页 在静态资源映射规则中已经讲解 Custom Favicon support (covered later in this document). favicon.icon 在静态资源映射规则中已经讲解 Automatic use of a ConfigurableWebBindingInitializer bean (see below). 我们可以配置一个ConfigurableWebBindingInitializer来替换默认的添加到容器 初始化WebDataBinder 请求数据JavaBean springmvc 扩展 springboot 自动配置远远不能满足我们的开发生产需要所以我们自己需要扩展一些功能 比如我们原来在springmvc的配置文件中写的 mvc:view‐controller path/hello view‐namesuccess/mvc:interceptorsmvc:interceptormvc:mapping path/hello/bean/bean/mvc:interceptor/mvc:interceptors我们都需要进行根据实际需要进行配置 If you want to keep those Spring Boot MVC customizations and make more MVC customizations (interceptors, formatters, view controllers, and other features), you can add your own Configuration class of type WebMvcConfigurer but without EnableWebMvc. 如果要保留这些Spring Boot MVC定制并进行更多的MVC定制拦截器格式化程序视图控制器和其他功能则可以添加自己的类型为WebMvcConfigurer的Configuration类但不添加EnableWebMvc。 Configuration public class MySpringMvcConfig implements WebMvcConfigurer {Overridepublic void addViewControllers(ViewControllerRegistry registry) {//浏览器发送hello 跳转到success页面registry.addViewController(/hello).setViewName(success);} } 编写一个配置类Configuration是WebMvcConfigurer 类型不能标注EnableWebMvc;老版本是WebMvcConfigurerAdapter,这个是抽象类没有都是空方法 既保留了所有的自动配置也能用我们扩展的配置 我们一探究竟 原理: WebMvcAutoConfiguration是SpringMVC的自动配置类、在做其他自动配置时会导入Import({WebMvcAutoConfiguration.EnableWebMvcConfiguration.class}) Configuration(proxyBeanMethods false)Import({WebMvcAutoConfiguration.EnableWebMvcConfiguration.class})EnableConfigurationProperties({WebMvcProperties.class, ResourceProperties.class})Order(0)public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer {EnableWebMvcConfiguration类 Configuration(proxyBeanMethods false)public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration implements ResourceLoaderAware {private final ResourceProperties resourceProperties;EnableWebMvcConfiguration父类中 public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {private final WebMvcConfigurerComposite configurers new WebMvcConfigurerComposite();public DelegatingWebMvcConfiguration() {}//从容器中获取所有的WebMvcConfigurerAutowired(required false)public void setConfigurers(ListWebMvcConfigurer configurers) {if (!CollectionUtils.isEmpty(configurers)) {this.configurers.addWebMvcConfigurers(configurers);}}//将所有的WebMvcConfigurer相关配置都来一起调用 public void addWebMvcConfigurers(ListWebMvcConfigurer configurers) {if (!CollectionUtils.isEmpty(configurers)) {this.delegates.addAll(configurers);}}、容器中所有的WebMvcConfigurer都会一起起作用 、我们的配置类也会被调用 效果SpringMVC的自动配置和我们的扩展配置都会起作用 注意这里说的都会起作用是说的针对不同的配置,比如是配置的静态文件映射,有的是viewController等等这些一起起作用 WebMvcRegistrations 如果要提供RequestMappingHandlerMappingRequestMappingHandlerAdapter或ExceptionHandlerExceptionResolver的自定义实例并且仍然保留Spring Boot MVC自定义则可以声明WebMvcRegistrations类型的Bean并使用它提供这些组件的自定义实例。 完全控制springmvc If you want to take complete control of Spring MVC, you can add your own Configuration annotated with EnableWebMvc, or alternatively add your own Configuration-annotated DelegatingWebMvcConfiguration as described in the Javadoc of EnableWebMvc. 如果要完全控制Spring MVC则可以添加用EnableWebMvc注释的自己的Configuration或者按照EnableWebMvc的Javadoc中的说明添加自己的Configuration注释的DelegatingWebMvcConfiguration。 原理: 为什么EnableWebMvc自动配置就失效了 EnableWebMvc Import({DelegatingWebMvcConfiguration.class}) public interface EnableWebMvc { }public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {这样看来是说明我们导入了WebMvcConfigurationSupport WebMvcAutoConfiguration 这个类我们知道是springmvc自动配置的核心类,在没有WebMvcConfigurationSupport这组件的时候才起作用 ConditionalOnClass({Servlet.class, DispatcherServlet.class, WebMvcConfigurer.class}) ConditionalOnMissingBean({WebMvcConfigurationSupport.class}) AutoConfigureOrder(-2147483638) AutoConfigureAfter({DispatcherServletAutoConfiguration.class, TaskExecutionAutoConfiguration.class, ValidationAutoConfiguration.class}) public class WebMvcAutoConfiguration {这么说来我们目前知道WebMvcAutoConfiguration类以及失效了 、导入的WebMvcConfigurationSupport只是SpringMVC最基本的功能 如何修改SpringBoot的默认配置 模式 1、SpringBoot在自动配置很多组件的时候先看容器中有没有用户自己配置的Bean、Component如果有就用用户配置的如果没有才自动配置如果有些组件可以有多个ViewResolver将用户配置的和自己默认的组合起来 2、在SpringBoot中会有非常多的xxxConfigurer帮助我们进行扩展配置 3、在SpringBoot中会有很多的xxxCustomizer帮助我们进行定制配置
http://www.hkea.cn/news/14423110/

相关文章:

  • 一个公司如何做多个网站备案页面效果设计
  • 陕西网站开发联系电话微商城建设
  • 做网站muse好还是DW好用济宁市建设工程质量监督站网站
  • 怎么免费建立自己的网站步骤网站建设商城制作
  • 提高网站规范化建设建立一个网站怎样赚钱
  • 大连网站策划网站开发 团队构成
  • 手机网站大全网址大全vue 做企业网站行不
  • 网站开发周期价格郑州个人做网站
  • 秦皇岛建设路小学网站宁波公司做网站
  • 免费网站域名注册珠海正规网站制作系统
  • 手机版网站模板 免费怎么在网上做广告宣传
  • 网站建设市场数据分析哪里有网站建设的文章
  • 湖南网站制作流程网站栏目和版块的设计心得
  • 免费免费建网站免费解析网站
  • 网站程序文件wordpress全站静态化
  • 苏州做网站公司 询苏州聚尚网络网站的困难
  • 百度 特定网站搜索seo值怎么提高
  • 江阴便宜做网站查互做蛋白的网站
  • 域名 不做网站wordpress如何添加分类目录
  • 建站公司 长沙和西安网页无法访问手机
  • 建网站要钱吗沈阳三好街网站建设
  • 微信订单网站模版微网站背景图片
  • 建立网站就是制作网页对吗建设网上商城网站
  • error 403 网站拒绝显示东莞关键词排名seo
  • 青海网站建设策划宁波开发投资有限公司
  • 网站建设教程网昆明seo外包
  • 用ftp改网站电话怎么内页底部的没有变无锡做网站seo的
  • 忆达城市建设游戏登录网站产品展示网站 模板
  • 企业网站建设综合实训心得体会一千字旅游网站设计页面
  • 上海网站建设 觉策动力wordpress主题dux