网站备案电话,现货黄金什么网站可以做直播,贵阳高端网站开发制作,怎么免费创建网站本文说点儿简单的。 如果你想研究基于 XML 配置的 spring mvc 的话#xff0c;可以简单扫一眼本文。
在基于 XML 配置的 spring mvc 开发中#xff0c;我们主要就是通过 spring 提供的各种标签来配置。 但是#xff0c;大家是不是都有个疑问#xff0c;spring 到底给我们提…本文说点儿简单的。 如果你想研究基于 XML 配置的 spring mvc 的话可以简单扫一眼本文。
在基于 XML 配置的 spring mvc 开发中我们主要就是通过 spring 提供的各种标签来配置。 但是大家是不是都有个疑问spring 到底给我们提供了多少标签都有哪些子元素有哪些属性有哪些
当然如果你对 XML 非常熟悉那简单直接看对应模块的 schema 文件就行了。 比如在 sping-webmvc 模块的 META-INF/spring.schemas 文件中就定义了如下这些 schema
http\://www.springframework.org/schema/mvc/spring-mvc-3.0.xsdorg/springframework/web/servlet/config/spring-mvc.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-3.1.xsdorg/springframework/web/servlet/config/spring-mvc.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-3.2.xsdorg/springframework/web/servlet/config/spring-mvc.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-4.0.xsdorg/springframework/web/servlet/config/spring-mvc.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-4.1.xsdorg/springframework/web/servlet/config/spring-mvc.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-4.2.xsdorg/springframework/web/servlet/config/spring-mvc.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-4.3.xsdorg/springframework/web/servlet/config/spring-mvc.xsd
http\://www.springframework.org/schema/mvc/spring-mvc.xsdorg/springframework/web/servlet/config/spring-mvc.xsd你点开这些链接研究其中的内容就行了比如 http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 这个文件内容如下只是部分
This XML file does not appear to have any style information associated with it. The document tree is shown below.
xsd:schema xmlnshttp://www.springframework.org/schema/mvc xmlns:xsdhttp://www.w3.org/2001/XMLSchema xmlns:beanshttp://www.springframework.org/schema/beans xmlns:toolhttp://www.springframework.org/schema/tool targetNamespacehttp://www.springframework.org/schema/mvc elementFormDefaultqualified attributeFormDefaultunqualified
xsd:import namespacehttp://www.springframework.org/schema/beans schemaLocationhttps://www.springframework.org/schema/beans/spring-beans-4.3.xsd/
xsd:import namespacehttp://www.springframework.org/schema/tool schemaLocationhttps://www.springframework.org/schema/tool/spring-tool-4.3.xsd/
xsd:element nameannotation-driven
xsd:annotation
xsd:documentation sourcejava:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
![CDATA[ Configures the annotation-driven Spring MVC Controller programming model. Note that this tag works in Web MVC only, not in Portlet MVC! See org.springframework.web.servlet.config.annotation.EnableWebMvc javadoc for details on code-based alternatives to enabling annotation-driven Spring MVC support. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:all minOccurs0
xsd:element namepath-matching minOccurs0
xsd:annotation
xsd:documentation
![CDATA[ Configures the path matching part of the Spring MVC Controller programming model. Like annotation-driven, code-based alternatives are also documented in EnableWebMvc javadoc. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:attribute namesuffix-pattern typexsd:boolean
xsd:annotation
xsd:documentation
![CDATA[ Whether to use suffix pattern match (.*) when matching patterns to requests. If enabled a method mapped to /users also matches to /users.*. The default value is true. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nametrailing-slash typexsd:boolean
xsd:annotation
xsd:documentation
![CDATA[ Whether to match to URLs irrespective of the presence of a trailing slash. If enabled a method mapped to /users also matches to /users/. The default value is true. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nameregistered-suffixes-only typexsd:boolean
xsd:annotation
xsd:documentation
![CDATA[ Whether suffix pattern matching should work only against path extensions explicitly registered when you configure content negotiation. This is generally recommended to reduce ambiguity and to avoid issues such as when a . appears in the path for other reasons. The default value is false. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute namepath-helper typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ The bean name of the UrlPathHelper to use for resolution of lookup paths. Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and MethodNameResolvers. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute namepath-matcher typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ The bean name of the PathMatcher implementation to use for matching URL paths against registered URL patterns. Default is AntPathMatcher. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
/xsd:complexType
/xsd:element
xsd:element namemessage-converters minOccurs0
xsd:annotation
xsd:documentation
![CDATA[ Configures one or more HttpMessageConverter types to use for converting RequestBody method parameters and ResponseBody method return values. Using this configuration element is optional. HttpMessageConverter registrations provided here will take precedence over HttpMessageConverter types registered by default. Also see the register-defaults attribute if you want to turn off default registrations entirely. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:sequence
xsd:choice maxOccursunbounded
xsd:element refbeans:bean
xsd:annotation
xsd:documentation
![CDATA[ An HttpMessageConverter bean definition. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
xsd:element refbeans:ref
xsd:annotation
xsd:documentation
![CDATA[ A reference to an HttpMessageConverter bean. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
/xsd:choice
/xsd:sequence
xsd:attribute nameregister-defaults typexsd:boolean defaulttrue
xsd:annotation
xsd:documentation
![CDATA[ Whether or not default HttpMessageConverter registrations should be added in addition to the ones provided within this element. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
/xsd:complexType
/xsd:element
xsd:element nameargument-resolvers minOccurs0
xsd:annotation
xsd:documentation
![CDATA[ Configures HandlerMethodArgumentResolver types to support custom controller method argument types. Using this option does not override the built-in support for resolving handler method arguments. To customize the built-in support for argument resolution configure RequestMappingHandlerAdapter directly. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:choice minOccurs1 maxOccursunbounded
xsd:element refbeans:bean minOccurs0 maxOccursunbounded
xsd:annotation
xsd:documentation
![CDATA[ The HandlerMethodArgumentResolver (or WebArgumentResolver for backwards compatibility) bean definition. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
xsd:element refbeans:ref minOccurs0 maxOccursunbounded
xsd:annotation
xsd:documentation
![CDATA[ A reference to a HandlerMethodArgumentResolver bean definition. ]]
/xsd:documentation
xsd:appinfo
tool:annotation kindref
tool:expected-type typejava:org.springframework.web.method.support.HandlerMethodArgumentResolver/
/tool:annotation
/xsd:appinfo
/xsd:annotation
/xsd:element
/xsd:choice
/xsd:complexType
/xsd:element
xsd:element namereturn-value-handlers minOccurs0
xsd:annotation
xsd:documentation
![CDATA[ Configures HandlerMethodReturnValueHandler types to support custom controller method return value handling. Using this option does not override the built-in support for handling return values. To customize the built-in support for handling return values configure RequestMappingHandlerAdapter directly. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:choice minOccurs1 maxOccursunbounded
xsd:element refbeans:bean minOccurs0 maxOccursunbounded
xsd:annotation
xsd:documentation
![CDATA[ The HandlerMethodReturnValueHandler bean definition. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
xsd:element refbeans:ref minOccurs0 maxOccursunbounded
xsd:annotation
xsd:documentation
![CDATA[ A reference to a HandlerMethodReturnValueHandler bean definition. ]]
/xsd:documentation
xsd:appinfo
tool:annotation kindref
tool:expected-type typejava:org.springframework.web.method.support.HandlerMethodReturnValueHandler/
/tool:annotation
/xsd:appinfo
/xsd:annotation
/xsd:element
/xsd:choice
/xsd:complexType
/xsd:element
xsd:element nameasync-support minOccurs0
xsd:annotation
xsd:documentation
![CDATA[ Configure options for asynchronous request processing. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:all minOccurs0
xsd:element namecallable-interceptors minOccurs0
xsd:annotation
xsd:documentation
![CDATA[ The ordered set of interceptors that intercept the lifecycle of concurrently executed requests, which start after a controller returns a java.util.concurrent.Callable. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:sequence
xsd:element refbeans:bean minOccurs1 maxOccursunbounded
xsd:annotation
xsd:documentation
![CDATA[ Registers a CallableProcessingInterceptor. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
/xsd:sequence
/xsd:complexType
/xsd:element
xsd:element namedeferred-result-interceptors minOccurs0
xsd:annotation
xsd:documentation
![CDATA[ The ordered set of interceptors that intercept the lifecycle of concurrently executed requests, which start after a controller returns a DeferredResult. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:sequence
xsd:element refbeans:bean minOccurs1 maxOccursunbounded
xsd:annotation
xsd:documentation
![CDATA[ Registers a DeferredResultProcessingInterceptor. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
/xsd:sequence
/xsd:complexType
/xsd:element
/xsd:all
xsd:attribute nametask-executor typexsd:string
xsd:annotation
xsd:documentation sourcejava:org.springframework.core.task.AsyncTaskExecutor
![CDATA[ The bean name of a default AsyncTaskExecutor to use when a controller method returns a {link Callable}. Controller methods can override this default on a per-request basis by returning an AsyncTask. By default, a SimpleAsyncTaskExecutor is used which does not re-use threads and is not recommended for production. ]]
/xsd:documentation
xsd:appinfo
tool:annotation kindref
tool:expected-type typejava:org.springframework.core.task.AsyncTaskExecutor/
/tool:annotation
/xsd:appinfo
/xsd:annotation
/xsd:attribute
xsd:attribute namedefault-timeout typexsd:long
xsd:annotation
xsd:documentation
![CDATA[ Specify the amount of time, in milliseconds, before asynchronous request handling times out. In Servlet 3, the timeout begins after the main request processing thread has exited and ends when the request is dispatched again for further processing of the concurrently produced result. If this value is not set, the default timeout of the underlying implementation is used, e.g. 10 seconds on Tomcat with Servlet 3. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
/xsd:complexType
/xsd:element
/xsd:all
xsd:attribute nameconversion-service typexsd:string
xsd:annotation
xsd:element refbeans:ref
xsd:annotation
xsd:documentation sourceorg.springframework.web.servlet.resource.ResourceResolver
![CDATA[ A reference to a ResourceResolver bean. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
/xsd:choice
/xsd:sequence
/xsd:complexType
xsd:complexType nameresource-transformers
xsd:annotation
xsd:documentation sourceorg.springframework.web.servlet.resource.ResourceTransformer
![CDATA[ A list of ResourceTransformer beans definition and references. A ResourceTransformer provides mechanisms for transforming the content of a resource. ]]
/xsd:documentation
/xsd:annotation
xsd:sequence
xsd:choice maxOccursunbounded
xsd:element refbeans:bean
xsd:annotation
xsd:documentation sourceorg.springframework.web.servlet.resource.ResourceTransformer
![CDATA[ A ResourceTransformer bean definition. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
xsd:element refbeans:ref
xsd:annotation
xsd:documentation sourceorg.springframework.web.servlet.resource.ResourceTransformer
![CDATA[ A reference to a ResourceTransformer bean. ]]
/xsd:documentation
/xsd:annotation
/xsd:element
/xsd:choice
/xsd:sequence
/xsd:complexType
xsd:complexType nameresource-chain
xsd:annotation
/xsd:attribute
xsd:attribute namecontent-type typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ Set the content type to use for the response (text/html by default). ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute namecharset typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ Set the charset used to read script and template files (UTF-8 by default). ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nameresource-loader-path typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ The script engine resource loader path via a Spring resource location. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nameshared-engine typexsd:boolean
xsd:annotation
xsd:documentation
![CDATA[ When set to false, use thread-local ScriptEngine instances instead of one single shared instance. This flag should be set to false for those using non thread-safe script engines with templating libraries not designed for concurrency, like Handlebars or React running on Nashorn for example. In this case, Java 8u60 or greater is required due to this bug: https://bugs.openjdk.java.net/browse/JDK-8076099. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
/xsd:complexType
/xsd:element
xsd:element namecors
xsd:annotation
xsd:documentation
![CDATA[ Configure cross origin requests processing. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:sequence
xsd:element namemapping minOccurs1 maxOccursunbounded
xsd:annotation
xsd:documentation
![CDATA[ Enable cross origin requests processing on the specified path pattern. By default, all origins, GET HEAD POST methods, all headers and credentials are allowed and max age is set to 30 minutes. ]]
/xsd:documentation
/xsd:annotation
xsd:complexType
xsd:attribute namepath typexsd:string userequired
xsd:annotation
xsd:documentation
![CDATA[ A path into the application that should handle CORS requests. Exact path mapping URIs (such as /admin) are supported as well as Ant-stype path patterns (such as /admin/**). ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nameallowed-origins typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ Comma-separated list of origins to allow, e.g. https://domain1.com, https://domain2.com. The special value * allows all domains (default). Note that CORS checks use values from Forwarded (RFC 7239), X-Forwarded-Host, X-Forwarded-Port, and X-Forwarded-Proto headers, if present, in order to reflect the client-originated address. Consider using the ForwardedHeaderFilter in order to choose from a central place whether to extract and use such headers, or whether to discard them. See the Spring Framework reference for more on this filter. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nameallowed-methods typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ Comma-separated list of HTTP methods to allow, e.g. GET, POST. The special value * allows all method. By default GET, HEAD and POST methods are allowed. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nameallowed-headers typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ Comma-separated list of headers that a pre-flight request can list as allowed for use during an actual request. The special value of * allows actual requests to send any header (default). ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nameexposed-headers typexsd:string
xsd:annotation
xsd:documentation
![CDATA[ Comma-separated list of response headers other than simple headers (i.e. Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma) that an actual response might have and can be exposed. Empty by default. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute nameallow-credentials typexsd:boolean
xsd:annotation
xsd:documentation
![CDATA[ Whether user credentials are supported (true by default). ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
xsd:attribute namemax-age typexsd:long
xsd:annotation
xsd:documentation
![CDATA[ How long, in seconds, the response from a pre-flight request can be cached by clients. 1800 seconds (30 minutes) by default. ]]
/xsd:documentation
/xsd:annotation
/xsd:attribute
/xsd:complexType
/xsd:element
/xsd:sequence
/xsd:complexType
/xsd:element
/xsd:schema从这个角度入手是没问题的。但是我感觉大多数人看了这种都头疼除非你精通 XML。
接下来可以看另外一个文件 META-INF/spring.handlers 。比如spring-webmvc 模块中这个文件内容如下
http\://www.springframework.org/schema/mvcorg.springframework.web.servlet.config.MvcNamespaceHandlerMvcNamespaceHandler 这个类的内容如下
/** Copyright 2002-2016 the original author or authors.** Licensed under the Apache License, Version 2.0 (the License);* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an AS IS BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.springframework.web.servlet.config;import org.springframework.beans.factory.xml.NamespaceHandler;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;/*** {link NamespaceHandler} for Spring MVC configuration namespace.** author Keith Donald* author Jeremy Grelle* author Sebastien Deleuze* since 3.0*/
public class MvcNamespaceHandler extends NamespaceHandlerSupport {Overridepublic void init() {registerBeanDefinitionParser(annotation-driven, new AnnotationDrivenBeanDefinitionParser());registerBeanDefinitionParser(default-servlet-handler, new DefaultServletHandlerBeanDefinitionParser());registerBeanDefinitionParser(interceptors, new InterceptorsBeanDefinitionParser());registerBeanDefinitionParser(resources, new ResourcesBeanDefinitionParser());registerBeanDefinitionParser(view-controller, new ViewControllerBeanDefinitionParser());registerBeanDefinitionParser(redirect-view-controller, new ViewControllerBeanDefinitionParser());registerBeanDefinitionParser(status-controller, new ViewControllerBeanDefinitionParser());registerBeanDefinitionParser(view-resolvers, new ViewResolversBeanDefinitionParser());registerBeanDefinitionParser(tiles-configurer, new TilesConfigurerBeanDefinitionParser());registerBeanDefinitionParser(freemarker-configurer, new FreeMarkerConfigurerBeanDefinitionParser());registerBeanDefinitionParser(groovy-configurer, new GroovyMarkupConfigurerBeanDefinitionParser());registerBeanDefinitionParser(script-template-configurer, new ScriptTemplateConfigurerBeanDefinitionParser());registerBeanDefinitionParser(cors, new CorsBeanDefinitionParser());}}
看到这是不是就清晰了。
mvc:annotation-driven/ 这个标签就是被类 AnnotationDrivenBeanDefinitionParser 解析的。以此类推。其他标签也是由对应的类解析的。
这里是以 spring-webmvc 模块为例来说的其他模块如 spring-beans 、spring-context 都有对应 META-INF/spring.handlers 文件。分别用于解析对应的命名空间下的标签。 解释下命名空间的意思就拿 mvc:annotation-driven/ 来说mvc 就是命名空间再比如 context:component-scan/ 这个标签context 就是命名空间。