GVKun编程网logo

xml 约束写法 -springMvc 参考(spring中xml约束有什么用)

18

如果您对xml约束写法-springMvc参考感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于xml约束写法-springMvc参考的详细内容,我们还将为您解答spring中

如果您对xml 约束写法 -springMvc 参考感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于xml 约束写法 -springMvc 参考的详细内容,我们还将为您解答spring中xml约束有什么用的相关问题,并且为您提供关于19. SpringBoot 扩展 SpringMVC功能、 接管、自定义SpringMVC、applicationContext-mvc.xml(Spring 集成 SpringMVC)配置文件、java day62【 响应数据和结果视图 、 SpringMVC 实现文件上传 、 SpringMVC 中的异常处理 、 SpringMVC 中的拦截器 】、JavaEE_Mybatis_SpringMVC_SpringMVC_lesson1_简单的SpringMVC框架搭建指南的有价值信息。

本文目录一览:

xml 约束写法 -springMvc 参考(spring中xml约束有什么用)

xml 约束写法 -springMvc 参考(spring中xml约束有什么用)

一.servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd  
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd  
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

	<context:annotation-config />
	
	<import resource=""/>
	<context:component-scan base-package="com.**.controller"></context:component-scan>

	<mvc:annotation-driven  validator="validator" /><!-- 开启注解:[json注解] ,添加validator校验-->


	<bean>
		<property name="prefix" value="/WEB-INF/" />
		<property name="suffix" value=".jsp" />
	</bean>
	<!-- 文件上传 -->
	<bean id="multipartResolver">
		<!-- 设置上传文件的最大尺寸为5MB -->
		<property name="maxUploadSize" value="20480" />
	</bean>

	<!--拦截器 -->
	<mvc:interceptors>
		<!--多个拦截器,顺序执行 -->
		<mvc:interceptor>
			<mvc:mapping path="/user/**" />
			<bean></bean>
		</mvc:interceptor>

		<mvc:interceptor>
			<mvc:mapping path="/user/**" />
			<bean></bean>
		</mvc:interceptor>
	</mvc:interceptors>
	<!-- end 拦截器 -->
	<!-- 校验器 ,validator需要 annotation_driven 注册 -->
	<bean id="validator">
		<!-- hibernate校验器 -->
		<property name="providerClass" value="org.hibernate.validator.HibernateValidator" />
		<!-- 指定校验使用的资源文件,在文件中配置校验错误信息,如果不指定则默认使用classpath下的ValidationMessages.properties -->
		<property name="validationMessageSource" ref="messageSource" />
	</bean>
	<!-- 校验错误信息配置文件 -->
	<bean id="messageSource">
		<!-- 资源文件名 -->
		<property name="basenames">
			<list>
				<value>classpath:CustomValidationMessages</value>
			</list>
		</property>
		<!-- 资源文件编码格式 -->
		<property name="fileEncodings" value="utf-8" />
		<!-- 对资源文件内容缓存时间,单位秒 -->
		<property name="cacheSeconds" value="120" />
	</bean>
	<!-- 校验配置完毕 -->

</beans>

 

二.xmlns="http://www.springframework.org/schema/beans"

 

 

 

xmlns="http://www.springframework.org/schema/beans"

点进去是

点击3.2.xsd.显示如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<xsd:schema xmlns="http://www.springframework.org/schema/beans"
		xmlns:xsd="http://www.w3.org/2001/XMLSchema"
		targetNamespace="http://www.springframework.org/schema/beans">

	<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>

	<xsd:annotation>
		<xsd:documentation><![CDATA[
	Spring XML Beans Schema, version 3.2
	Authors: Juergen Hoeller, Rob Harrop, Mark Fisher, Chris Beams

	This defines a simple and consistent way of creating a namespace
	of JavaBeans objects, managed by a Spring BeanFactory, read by
	XmlBeanDefinitionReader (with DefaultBeanDefinitionDocumentReader).

	This document type is used by most Spring functionality, including
	web application contexts, which are based on bean factories.

	Each "bean" element in this document defines a JavaBean.
	Typically the bean class is specified, along with JavaBean properties
	and/or constructor arguments.

	A bean instance can be a "singleton" (shared instance) or a "prototype"
	(independent instance). Further scopes can be provided by extended
	bean factories, for example in a web environment.

	References among beans are supported, that is, setting a JavaBean property
	or a constructor argument to refer to another bean in the same factory
	(or an ancestor factory).

	As alternative to bean references, "inner bean definitions" can be used.
	Singleton flags of such inner bean definitions are effectively ignored:
	inner beans are typically anonymous prototypes.

	There is also support for lists, sets, maps, and java.util.Properties
	as bean property types or constructor argument types.
		]]></xsd:documentation>
	</xsd:annotation>

	<!-- base types -->
	<xsd:complexType name="identifiedType" abstract="true">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	The unique identifier for a bean. The scope of the identifier
	is the enclosing bean factory.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:attribute name="id" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The unique identifier for a bean. A bean id may not be used more than once
	within the same <beans> element.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
	</xsd:complexType>

	<!-- Top-level <beans> tag -->
	<xsd:element name="beans">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Container for <bean> and other elements, typically the root element in the document.
	Allows the definition of default values for all nested bean definitions. May itself
	be nested for the purpose of defining a subset of beans with certain default values or
	to be registered only when certain profile(s) are active. Any such nested <beans> element
	must be declared as the last element in the document.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="description" minOccurs="0"/>
				<xsd:choice minOccurs="0" maxOccurs="unbounded">
					<xsd:element ref="import"/>
					<xsd:element ref="alias"/>
					<xsd:element ref="bean"/>
					<xsd:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
				</xsd:choice>
				<xsd:element ref="beans" minOccurs="0" maxOccurs="unbounded"/>
			</xsd:sequence>
			<xsd:attribute name="profile" use="optional" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The set of profiles for which this <beans> element should be parsed. Multiple profiles
	can be separated by spaces, commas, or semi-colons.

	If one or more of the specified profiles are active at time of parsing, the <beans>
	element will be parsed, and all of its <bean> elements registered, &lt;import&gt;
	elements followed, etc.  If none of the specified profiles are active at time of
	parsing, then the entire element and its contents will be ignored.

	If a profile is prefixed with the NOT operator ''!'', e.g.

		<beans profile="p1,!p2">

	indicates that the <beans> element should be parsed if profile "p1" is active or
	if profile "p2" is not active.

	Profiles are activated in one of two ways:
		Programmatic:
			ConfigurableEnvironment#setActiveProfiles(String...)
			ConfigurableEnvironment#setDefaultProfiles(String...)

		Properties (typically through -D system properties, environment variables, or
		servlet context init params):
			spring.profiles.active=p1,p2
			spring.profiles.default=p1,p2
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="default-lazy-init" default="default" type="defaultable-boolean">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The default ''lazy-init'' value; see the documentation for the
	''lazy-init'' attribute of the ''bean'' element.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="default-merge" default="default" type="defaultable-boolean">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The default ''merge'' value; see the documentation for the
	''merge'' attribute of the various collection elements. The default
	is ''false''.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="default-autowire" default="default">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The default ''autowire'' value; see the documentation for the
	''autowire'' attribute of the ''bean'' element. The default is ''default''.
					]]></xsd:documentation>
				</xsd:annotation>
				<xsd:simpleType>
					<xsd:restriction base="xsd:NMTOKEN">
						<xsd:enumeration value="default"/>
						<xsd:enumeration value="no"/>
						<xsd:enumeration value="byName"/>
						<xsd:enumeration value="byType"/>
						<xsd:enumeration value="constructor"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:attribute>
			<xsd:attribute name="default-autowire-candidates" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	A default bean name pattern for identifying autowire candidates:
	e.g. "*Service", "data*", "*Service*", "data*Service".
	Also accepts a comma-separated list of patterns: e.g. "*Service,*Dao".
	See the documentation for the ''autowire-candidate'' attribute of the
	''bean'' element for the semantic details of autowire candidate beans.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="default-init-method" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The default ''init-method'' value; see the documentation for the
	''init-method'' attribute of the ''bean'' element.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="default-destroy-method" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The default ''destroy-method'' value; see the documentation for the
	''destroy-method'' attribute of the ''bean'' element.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:anyAttribute namespace="##other" processContents="lax"/>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="description">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Contains informative text describing the purpose of the enclosing element.
	Used primarily for user documentation of XML bean definition documents.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType mixed="true">
			<xsd:choice minOccurs="0" maxOccurs="unbounded"/>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="import">
		<xsd:annotation>
			<xsd:documentation source="java:org.springframework.core.io.Resource"><![CDATA[
	Specifies an XML bean definition resource to import.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:restriction base="xsd:anyType">
					<xsd:attribute name="resource" type="xsd:string" use="required">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The relative resource location of the XML (bean definition) file to import,
	for example "myImport.xml" or "includes/myImport.xml" or "../myImport.xml".
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:restriction>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="alias">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Defines an alias for a bean (which can reside in a different definition
	resource).
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:restriction base="xsd:anyType">
					<xsd:attribute name="name" type="xsd:string" use="required">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The name of the bean to define an alias for.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="alias" type="xsd:string" use="required">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The alias name to define for the bean.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:restriction>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:group name="beanElements">
		<xsd:sequence>
			<xsd:element ref="description" minOccurs="0"/>
			<xsd:choice minOccurs="0" maxOccurs="unbounded">
				<xsd:element ref="meta"/>
				<xsd:element ref="constructor-arg"/>
				<xsd:element ref="property"/>
				<xsd:element ref="qualifier"/>
				<xsd:element ref="lookup-method"/>
				<xsd:element ref="replaced-method"/>
				<xsd:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
			</xsd:choice>
		</xsd:sequence>
	</xsd:group>

	<xsd:attributeGroup name="beanAttributes">
		<xsd:attribute name="name" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	Can be used to create one or more aliases illegal in an (XML) id.
	Multiple aliases can be separated by any number of spaces, commas,
	or semi-colons (or indeed any mixture of the three).
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="class" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation source="java:java.lang.Class"><![CDATA[
	The fully qualified name of the bean''s class, except if it serves only
	as a parent definition for child bean definitions.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="parent" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The name of the parent bean definition.

	Will use the bean class of the parent if none is specified, but can
	also override it. In the latter case, the child bean class must be
	compatible with the parent, i.e. accept the parent''s property values
	and constructor argument values, if any.

	A child bean definition will inherit constructor argument values,
	property values and method overrides from the parent, with the option
	to add new values. If init method, destroy method, factory bean and/or
	factory method are specified, they will override the corresponding
	parent settings.

	The remaining settings will always be taken from the child definition:
	depends on, autowire mode, scope, lazy init.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="scope" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The scope of this bean: typically "singleton" (one shared instance,
	which will be returned by all calls to getBean with the given id), or
	"prototype" (independent instance resulting from each call to getBean).

	By default, a bean will be a singleton, unless the bean has a parent
	bean definition in which case it will inherit the parent''s scope.

	Singletons are most commonly used, and are ideal for multi-threaded
	service objects. Further scopes, such as "request" or "session", might
	be supported by extended bean factories (e.g. in a web environment).

	Inner bean definitions inherit the singleton status of their containing
	bean definition, unless explicitly specified: The inner bean will be a
	singleton if the containing bean is a singleton, and a prototype if
	the containing bean has any other scope.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="abstract" type="xsd:boolean">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	Is this bean "abstract", that is, not meant to be instantiated itself
	but rather just serving as parent for concrete child bean definitions?
	The default is "false". Specify "true" to tell the bean factory to not
	try to instantiate that particular bean in any case.

	Note: This attribute will not be inherited by child bean definitions.
	Hence, it needs to be specified per abstract bean definition.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="lazy-init" default="default" type="defaultable-boolean">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	Indicates whether or not this bean is to be lazily initialized.
	If false, it will be instantiated on startup by bean factories
	that perform eager initialization of singletons. The default is
	"false".

	Note: This attribute will not be inherited by child bean definitions.
	Hence, it needs to be specified per concrete bean definition.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="autowire" default="default">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	Controls whether bean properties are "autowired".
	This is an automagical process in which bean references don''t need
	to be coded explicitly in the XML bean definition file, but rather the
	Spring container works out dependencies.

	There are 4 modes:

	1. "no"
	The traditional Spring default. No automagical wiring. Bean references
	must be defined in the XML file via the <ref/> element (or "ref"
	attribute). We recommend this in most cases as it makes documentation
	more explicit.

	Note that this default mode also allows for annotation-driven autowiring,
	if activated. "no" refers to externally driven autowiring only, not
	affecting any autowiring demands that the bean class itself expresses.

	2. "byName"
	Autowiring by property name. If a bean of class Cat exposes a "dog"
	property, Spring will try to set this to the value of the bean "dog"
	in the current container. If there is no matching bean by name, nothing
	special happens.

	3. "byType"
	Autowiring if there is exactly one bean of the property type in the
	container. If there is more than one, a fatal error is raised, and
	you cannot use byType autowiring for that bean. If there is none,
	nothing special happens.

	4. "constructor"
	Analogous to "byType" for constructor arguments. If there is not exactly
	one bean of the constructor argument type in the bean factory, a fatal
	error is raised.

	Note that explicit dependencies, i.e. "property" and "constructor-arg"
	elements, always override autowiring.

	Note: This attribute will not be inherited by child bean definitions.
	Hence, it needs to be specified per concrete bean definition.
				]]></xsd:documentation>
			</xsd:annotation>
			<xsd:simpleType>
				<xsd:restriction base="xsd:NMTOKEN">
					<xsd:enumeration value="default"/>
					<xsd:enumeration value="no"/>
					<xsd:enumeration value="byName"/>
					<xsd:enumeration value="byType"/>
					<xsd:enumeration value="constructor"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="depends-on" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The names of the beans that this bean depends on being initialized.
	The bean factory will guarantee that these beans get initialized
	before this bean.

	Note that dependencies are normally expressed through bean properties
	or constructor arguments. This property should just be necessary for
	other kinds of dependencies like statics (*ugh*) or database preparation
	on startup.

	Note: This attribute will not be inherited by child bean definitions.
	Hence, it needs to be specified per concrete bean definition.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="autowire-candidate" default="default" type="defaultable-boolean">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	Indicates whether or not this bean should be considered when looking
	for matching candidates to satisfy another bean''s autowiring requirements.
	Note that this does not affect explicit references by name, which will get
	resolved even if the specified bean is not marked as an autowire candidate.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="primary" type="xsd:boolean">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	Specifies that this bean should be given preference when multiple
	candidates are qualified to autowire a single-valued dependency.
	If exactly one ''primary'' bean exists among the candidates, it
	will be the autowired value.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="init-method" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The name of the custom initialization method to invoke after setting
	bean properties. The method must have no arguments, but may throw any
	exception.

	This is an alternative to implementing Spring''s InitializingBean
	interface or marking a method with the PostConstruct annotation.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="destroy-method" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The name of the custom destroy method to invoke on bean factory shutdown.
	The method must have no arguments, but may throw any exception.

	This is an alternative to implementing Spring''s DisposableBean
	interface or the standard Java Closeable/AutoCloseable interface,
	or marking a method with the PreDestroy annotation.

	Note: Only invoked on beans whose lifecycle is under the full
	control of the factory - which is always the case for singletons,
	but not guaranteed for any other scope.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="factory-method" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The name of a factory method to use to create this object. Use
	constructor-arg elements to specify arguments to the factory method,
	if it takes arguments. Autowiring does not apply to factory methods.

	If the "class" attribute is present, the factory method will be a static
	method on the class specified by the "class" attribute on this bean
	definition. Often this will be the same class as that of the constructed
	object - for example, when the factory method is used as an alternative
	to a constructor. However, it may be on a different class. In that case,
	the created object will *not* be of the class specified in the "class"
	attribute. This is analogous to FactoryBean behavior.

	If the "factory-bean" attribute is present, the "class" attribute is not
	used, and the factory method will be an instance method on the object
	returned from a getBean call with the specified bean name. The factory
	bean may be defined as a singleton or a prototype.

	The factory method can have any number of arguments. Autowiring is not
	supported. Use indexed constructor-arg elements in conjunction with the
	factory-method attribute.

	Setter Injection can be used in conjunction with a factory method.
	Method Injection cannot, as the factory method returns an instance,
	which will be used when the container creates the bean.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="factory-bean" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	Alternative to class attribute for factory-method usage.
	If this is specified, no class attribute should be used.
	This must be set to the name of a bean in the current or
	ancestor factories that contains the relevant factory method.
	This allows the factory itself to be configured using Dependency
	Injection, and an instance (rather than static) method to be used.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:anyAttribute namespace="##other" processContents="lax"/>
	</xsd:attributeGroup>

	<xsd:element name="meta" type="metaType">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Arbitrary metadata attached to a bean definition.
			]]></xsd:documentation>
		</xsd:annotation>
	</xsd:element>

	<xsd:complexType name="metaType">
		<xsd:attribute name="key" type="xsd:string" use="required">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The key name of the metadata attribute being defined.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="value" type="xsd:string" use="required">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The value of the metadata attribute being defined (as a simple String).
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
	</xsd:complexType>

	<xsd:element name="bean">
		<xsd:annotation>
			<xsd:documentation source="java:org.springframework.beans.factory.config.BeanDefinition"><![CDATA[
	Defines a single (usually named) bean.

	A bean definition may contain nested tags for constructor arguments,
	property values, lookup methods, and replaced methods. Mixing constructor
	injection and setter injection on the same bean is explicitly supported.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="identifiedType">
					<xsd:group ref="beanElements"/>
					<xsd:attributeGroup ref="beanAttributes"/>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="constructor-arg">
		<xsd:annotation>
			<xsd:documentation source="java:org.springframework.beans.factory.config.ConstructorArgumentValues">
				<![CDATA[
	Bean definitions can specify zero or more constructor arguments.
	This is an alternative to "autowire constructor".
	Arguments correspond to either a specific index of the constructor
	argument list or are supposed to be matched generically by type.

	Note: A single generic argument value will just be used once, rather
	than potentially matched multiple times (as of Spring 1.1).

	constructor-arg elements are also used in conjunction with the
	factory-method element to construct beans using static or instance
	factory methods.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="description" minOccurs="0"/>
				<xsd:choice minOccurs="0" maxOccurs="1">
					<xsd:element ref="bean"/>
					<xsd:element ref="ref"/>
					<xsd:element ref="idref"/>
					<xsd:element ref="value"/>
					<xsd:element ref="null"/>
					<xsd:element ref="array"/>
					<xsd:element ref="list"/>
					<xsd:element ref="set"/>
					<xsd:element ref="map"/>
					<xsd:element ref="props"/>
					<xsd:any namespace="##other" processContents="strict"/>
				</xsd:choice>
			</xsd:sequence>
			<xsd:attribute name="index" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The exact index of the argument in the constructor argument list.
	Only needed to avoid ambiguities, e.g. in case of 2 arguments of
	the exact same type.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="type" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The exact type of the constructor argument. Only needed to avoid
	ambiguities, e.g. in case of 2 single argument constructors
	that can both be converted from a String.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="name" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The exact name of the argument in the constructor argument list.
	Only needed to avoid ambiguities, e.g. in case of 2 arguments of
	the exact same type. Note: This requires debug symbols to be
	stored in the class file in order to introspect argument names!
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="ref" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	A short-cut alternative to a nested "<ref bean=''...''/>" element.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="value" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	A short-cut alternative to a nested "<value>...<value/>" element.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="property" type="propertyType">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Bean definitions can have zero or more properties.
	Property elements correspond to JavaBean setter methods exposed
	by the bean classes. Spring supports primitives, references to other
	beans in the same or related factories, lists, maps and properties.
			]]></xsd:documentation>
		</xsd:annotation>
	</xsd:element>

	<xsd:element name="qualifier">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Bean definitions can provide qualifiers to match against annotations
	on a field or parameter for fine-grained autowire candidate resolution.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="attribute" minOccurs="0" maxOccurs="unbounded"/>
			</xsd:sequence>
			<xsd:attribute name="type" type="xsd:string" default="org.springframework.beans.factory.annotation.Qualifier"/>
			<xsd:attribute name="value" type="xsd:string"/>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="attribute" type="metaType">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	A qualifier element may contain attribute child elements as key-value
	pairs. These will be available for matching against attributes of a
	qualifier annotation on an autowired field or parameter if present.
			]]></xsd:documentation>
		</xsd:annotation>
	</xsd:element>

	<xsd:element name="lookup-method">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	A lookup method causes the IoC container to override the given method
	and return the bean with the name given in the bean attribute. This is
	a form of Method Injection. It is particularly useful as an alternative
	to implementing the BeanFactoryAware interface, in order to be able to
	make getBean() calls for non-singleton instances at runtime. In this
	case, Method Injection is a less invasive alternative.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:restriction base="xsd:anyType">
					<xsd:attribute name="name" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The name of the lookup method. This method must take no arguments.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="bean" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The name of the bean in the current or ancestor factories that
	the lookup method should resolve to. Often this bean will be a
	prototype, in which case the lookup method will return a distinct
	instance on every invocation. This is useful for single-threaded objects.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:restriction>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="replaced-method">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Similar to the lookup method mechanism, the replaced-method element
	is used to control IoC container method overriding: Method Injection.
	This mechanism allows the overriding of a method with arbitrary code.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:sequence>
				<xsd:choice minOccurs="0" maxOccurs="unbounded">
					<xsd:element ref="arg-type"/>
				</xsd:choice>
			</xsd:sequence>
			<xsd:attribute name="name" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The name of the method whose implementation must be replaced by the
	IoC container. If this method is not overloaded, there is no need
	to use arg-type subelements. If this method is overloaded, arg-type
	subelements must be used for all override definitions for the method.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
			<xsd:attribute name="replacer" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation source="java:org.springframework.beans.factory.support.MethodReplacer"><![CDATA[
	Bean name of an implementation of the MethodReplacer interface in the
	current or ancestor factories. This may be a singleton or prototype
	bean. If it is a prototype, a new instance will be used for each
	method replacement. Singleton usage is the norm.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="arg-type">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Identifies an argument for a replaced method in the event of
	method overloading.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType mixed="true">
			<xsd:choice minOccurs="0" maxOccurs="unbounded"/>
			<xsd:attribute name="match" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	Specification of the type of an overloaded method argument as a String.
	For convenience, this may be a substring of the FQN. E.g. all the
	following would match "java.lang.String":
	- java.lang.String
	- String
	- Str

	As the number of arguments will be checked also, this convenience
	can often be used to save typing.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="ref">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Defines a reference to another bean in this factory or an external
	factory (parent or included factory).
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:restriction base="xsd:anyType">
					<xsd:attribute name="bean" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The name of the referenced bean.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="local" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The name of the referenced bean. The value must be a bean ID and will be
	checked by the Spring container. This is therefore the preferred technique
	for referencing beans within the same bean factory XML file.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="parent" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The name of the referenced bean in a parent factory.
						]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:restriction>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="idref">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	The id of another bean in this factory or an external factory
	(parent or included factory).
	While a regular ''value'' element could instead be used for the
	same effect, using idref indicates that the Spring container
	should check that the value actually corresponds to a bean id.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:restriction base="xsd:anyType">
					<xsd:attribute name="bean" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The name of the referenced bean.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="local" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	The name of the referenced bean. The value must be a bean ID and will be
	checked by the Spring container. This is therefore the preferred technique
	for referencing beans within the same bean factory XML file.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:restriction>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="value">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Contains a string representation of a property value.
	The property may be a string, or may be converted to the required
	type using the JavaBeans PropertyEditor machinery. This makes it
	possible for application developers to write custom PropertyEditor
	implementations that can convert strings to arbitrary target objects.

	Note that this is recommended for simple objects only. Configure
	more complex objects by populating JavaBean properties with
	references to other beans.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType mixed="true">
			<xsd:choice minOccurs="0" maxOccurs="unbounded"/>
			<xsd:attribute name="type" type="xsd:string">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The exact type that the value should be converted to. Only needed
	if the type of the target property or constructor argument is
	too generic: for example, in case of a collection element.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="null">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Denotes a Java null value. Necessary because an empty "value" tag
	will resolve to an empty String, which will not be resolved to a
	null value unless a special PropertyEditor does so.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType mixed="true">
			<xsd:choice minOccurs="0" maxOccurs="unbounded"/>
		</xsd:complexType>
	</xsd:element>

	<!-- Collection Elements -->
	<xsd:group name="collectionElements">
		<xsd:sequence>
			<xsd:element ref="description" minOccurs="0"/>
			<xsd:choice minOccurs="0" maxOccurs="unbounded">
				<xsd:element ref="bean"/>
				<xsd:element ref="ref"/>
				<xsd:element ref="idref"/>
				<xsd:element ref="value"/>
				<xsd:element ref="null"/>
				<xsd:element ref="array"/>
				<xsd:element ref="list"/>
				<xsd:element ref="set"/>
				<xsd:element ref="map"/>
				<xsd:element ref="props"/>
				<xsd:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
			</xsd:choice>
		</xsd:sequence>
	</xsd:group>

	<xsd:element name="array">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	An array can contain multiple inner bean, ref, collection, or value elements.
	This configuration element will always result in an array, even when being
	defined e.g. as a value for a map with value type Object.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="listOrSetType">
					<xsd:attribute name="merge" default="default" type="defaultable-boolean">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	Enables/disables merging for collections when using parent/child beans.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="list">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	A list can contain multiple inner bean, ref, collection, or value elements.
	A list can also map to an array type; the necessary conversion is performed
	automatically.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="listOrSetType">
					<xsd:attribute name="merge" default="default" type="defaultable-boolean">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	Enables/disables merging for collections when using parent/child beans.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="set">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	A set can contain multiple inner bean, ref, collection, or value elements.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="listOrSetType">
					<xsd:attribute name="merge" default="default" type="defaultable-boolean">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	Enables/disables merging for collections when using parent/child beans.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="map">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	A mapping from a key to an object. Maps may be empty.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="mapType">
					<xsd:attribute name="merge" default="default" type="defaultable-boolean">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	Enables/disables merging for collections when using parent/child beans.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="entry" type="entryType">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	A map entry can be an inner bean, ref, value, or collection.
	The key of the entry is given by the "key" attribute or child element.
			]]></xsd:documentation>
		</xsd:annotation>
	</xsd:element>

	<xsd:element name="props">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	Props elements differ from map elements in that values must be strings.
	Props may be empty.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="propsType">
					<xsd:attribute name="merge" default="default" type="defaultable-boolean">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
	Enables/disables merging for collections when using parent/child beans.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="key">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	A key element can contain an inner bean, ref, value, or collection.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:group ref="collectionElements"/>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="prop">
		<xsd:annotation>
			<xsd:documentation><![CDATA[
	The string value of the property. Note that whitespace is trimmed
	off to avoid unwanted whitespace caused by typical XML formatting.
			]]></xsd:documentation>
		</xsd:annotation>
		<xsd:complexType mixed="true">
			<xsd:choice minOccurs="0" maxOccurs="unbounded"/>
			<xsd:attribute name="key" type="xsd:string" use="required">
				<xsd:annotation>
					<xsd:documentation><![CDATA[
	The key of the property entry.
					]]></xsd:documentation>
				</xsd:annotation>
			</xsd:attribute>
		</xsd:complexType>
	</xsd:element>

	<xsd:complexType name="propertyType">
		<xsd:sequence>
			<xsd:element ref="description" minOccurs="0"/>
			<xsd:choice minOccurs="0" maxOccurs="1">
				<xsd:element ref="meta"/>
				<xsd:element ref="bean"/>
				<xsd:element ref="ref"/>
				<xsd:element ref="idref"/>
				<xsd:element ref="value"/>
				<xsd:element ref="null"/>
				<xsd:element ref="array"/>
				<xsd:element ref="list"/>
				<xsd:element ref="set"/>
				<xsd:element ref="map"/>
				<xsd:element ref="props"/>
				<xsd:any namespace="##other" processContents="strict"/>
			</xsd:choice>
		</xsd:sequence>
		<xsd:attribute name="name" type="xsd:string" use="required">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	The name of the property, following JavaBean naming conventions.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="ref" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	A short-cut alternative to a nested "<ref bean=''...''/>".
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="value" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	A short-cut alternative to a nested "<value>...</value>" element.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
	</xsd:complexType>

	<!-- Collection Types -->

	<!-- base type for collections that have (possibly) typed nested values -->
	<xsd:complexType name="collectionType">
		<xsd:attribute name="value-type" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation source="java:java.lang.Class"><![CDATA[
	The default Java type for nested values. Must be a fully qualified
	class name.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
	</xsd:complexType>

	<!-- ''list'' and ''set'' collection type -->
	<xsd:complexType name="listOrSetType">
		<xsd:complexContent>
			<xsd:extension base="collectionType">
				<xsd:group ref="collectionElements"/>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>

	<!-- ''map'' element type -->
	<xsd:complexType name="mapType">
		<xsd:complexContent>
			<xsd:extension base="collectionType">
				<xsd:sequence>
					<xsd:element ref="description" minOccurs="0"/>
					<xsd:choice minOccurs="0" maxOccurs="unbounded">
						<xsd:element ref="entry"/>
					</xsd:choice>
				</xsd:sequence>
				<xsd:attribute name="key-type" type="xsd:string">
					<xsd:annotation>
						<xsd:documentation source="java:java.lang.Class"><![CDATA[
	The default Java type for nested entry keys. Must be a fully qualified
	class name.
						]]></xsd:documentation>
					</xsd:annotation>
				</xsd:attribute>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>

	<!-- ''entry'' element type -->
	<xsd:complexType name="entryType">
		<xsd:sequence>
			<xsd:element ref="key" minOccurs="0"/>
			<xsd:group ref="collectionElements"/>
		</xsd:sequence>
		<xsd:attribute name="key" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	Each map element must specify its key as attribute or as child element.
	A key attribute is always a String value.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="key-ref" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	A short-cut alternative to a to a "key" element with a nested
	"<ref bean=''...''/>".
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="value" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	A short-cut alternative to a nested "<value>...</value>"
	element.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="value-ref" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	A short-cut alternative to a nested "<ref bean=''...''/>".
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="value-type" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation><![CDATA[
	A short-cut alternative to a ''type'' attribute on a nested
	"<value type=''...'' >...</value>" element.
				]]></xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
	</xsd:complexType>

	<!-- ''props'' collection type -->
	<xsd:complexType name="propsType">
		<xsd:complexContent>
			<xsd:extension base="collectionType">
				<xsd:sequence>
					<xsd:choice minOccurs="0" maxOccurs="unbounded">
						<xsd:element ref="prop"/>
					</xsd:choice>
				</xsd:sequence>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>

	<!-- simple internal types -->
	<xsd:simpleType name="defaultable-boolean">
		<xsd:restriction base="xsd:NMTOKEN">
			<xsd:enumeration value="default"/>
			<xsd:enumeration value="true"/>
			<xsd:enumeration value="false"/>
		</xsd:restriction>
	</xsd:simpleType>

</xsd:schema>

 

 

 

 

 

19. SpringBoot 扩展 SpringMVC功能、 接管、自定义SpringMVC

19. SpringBoot 扩展 SpringMVC功能、 接管、自定义SpringMVC

编写一个配置类(@Configuration),是WebMvcConfigurerAdapter类型;不能标注@EnableWebMv:
既保留了所有的自动配置,也能用我们扩展的配置;

如下代码:【拓展 请求 映射 页面  功能】

//使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
// super.addViewControllers(registry);
//浏览器发送 /bihu 请求来到 Thymeleaf 页面
        registry.addViewController("/bihu").setViewName("Thymeleaf");
    }
}

原理:

1)、WebMvcAutoConfiguration是SpringMVC的自动配置类

2)、在做其他自动配置时会导入;@Import(EnableWebMvcConfiguration.class)

@Configuration
public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration {
private final WebMvcConfigurerComposite configurers = new WebMvcConfigurerComposite();
//从容器中获取所有的WebMvcConfigurer
@Autowired(required = false)
public void setConfigurers(List<WebMvcConfigurer> configurers) {
if (!CollectionUtils.isEmpty(configurers)) {
this.configurers.addWebMvcConfigurers(configurers);
//一个参考实现;将所有的WebMvcConfigurer相关配置都来一起调用;
@Override
// public void addViewControllers(ViewControllerRegistry registry) {
// for (WebMvcConfigurer delegate : this.delegates) {
// delegate.addViewControllers(registry);
// }
}
}
}
EnableWebMvcConfiguration

3)、所以:容器中所有的WebMvcConfigurer都会一起起作用;

4)、我们的配置类也会被调用;

效果:SpringMVC的自动配置和我们的扩展配置都会起作用;

 

所以这就达成了 拓展SpringBoot 中 SpringMVC的功能

 



 

全面接管SpringBoot中的 SpringMVC:

SpringBoot对SpringMVC的自动配置不需要了,所有都是我们自己配置;所有的SpringMVC的自动配置都失效了

我们需要在配置类中添加@EnableWebMvc即可;

package com.bihu.springboot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

//使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能
//使用EnableWebMvc注解后 SpringBoot中SpringMVC的配置全部失效 都需要自己配,例如 下面的  请求bihu  跳到Thymeleaf页面 就是自己配的,,,你如果在static放(静态资源目录)html,也不可以直接访问
@EnableWebMvc
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
// super.addViewControllers(registry);
//浏览器发送 /bihu 请求来到 Thymeleaf
        registry.addViewController("/bihu").setViewName("Thymeleaf");
    }
}

原理: 为什么@EnableWebMvc自动配置就失效了;

1)@EnableWebMvc的核心

@Import(DelegatingWebMvcConfiguration.class)
public @interface EnableWebMvc {

2)、

@Configuration
public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {

3)、

@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass({ Servlet.class, dispatcherServlet.class,
WebMvcConfigurerAdapter.class })
//容器中没有这个组件的时候,这个自动配置类才生效  主要看这里!!!!这个条件注解这里
@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10)
@AutoConfigureAfter({ dispatcherServletAutoConfiguration.class,
ValidationAutoConfiguration.class })
public class WebMvcAutoConfiguration {

4)、@EnableWebMvc将WebMvcConfigurationSupport组件导入进来;

5)、导入的WebMvcConfigurationSupport只是SpringMVC最基本的功能;

 

如何修改SpringBoot的默认配置

模式: 1)、SpringBoot在自动配置很多组件的时候,先看容器中有没有用户自己配置的(@Bean、@Component)如 果有就用用户配置的,如果没有,才自动配置;如果有些组件可以有多个(ViewResolver)将用户配置的和自己默 认的组合起来;

2)、在SpringBoot中会有非常多的xxxConfigurer帮助我们进行扩展配置

3)、在SpringBoot中会有很多的xxxCustomizer帮助我们进行定制配置

 

applicationContext-mvc.xml(Spring 集成 SpringMVC)配置文件

applicationContext-mvc.xml(Spring 集成 SpringMVC)配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--扫描controller注解-->
    <context:component-scan base-package="cn.meco.aisell.web" />
    <!--扫描conmmon包注解-->
    <context:component-scan base-package="cn.meco.aisell.common" />

    <!-- 扫描easypoi的一些view:视图 -->
    <context:component-scan base-package="cn.afterturn.easypoi.view" />

    <!--开启spring-mvc注解-->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json; charset=UTF-8</value>
                        <value>application/x-www-form-urlencoded; charset=UTF-8</value>
                    </list>
                </property>
                <!-- No serializer:配置 objectMapper 为我们自定义扩展后的 CustomMapper,解决了返回对象有关系对象的报错问题 -->
                <property name="objectMapper">
                    <bean class="cn.meco.aisell.common.CustomMapper"></bean>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>


    <!--静态资源放行-->
    <mvc:default-servlet-handler />

    <!--视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!--文件上传解析器-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!--设置上传文件最大为10MB-->
        <property name="maxUploadSize">
            <value>10485760</value>
        </property>
    </bean>

    <!-- bean的视图解析器  p:order="0":顺序在最前面 -->
    <bean id="beanNameViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver"
          p:order="0" />

</beans>

 

java day62【 响应数据和结果视图 、 SpringMVC 实现文件上传 、 SpringMVC 中的异常处理 、 SpringMVC 中的拦截器 】

java day62【 响应数据和结果视图 、 SpringMVC 实现文件上传 、 SpringMVC 中的异常处理 、 SpringMVC 中的拦截器 】

第 1 章 响应数据和结果视图

1.1 返回值分类

1.1.1 字符串

1.1.2 void

1.1.3 ModelAndView

1.2 转发和重定向

1.2.1 forward 转发

1.2.2 Redirect 重定向

1.3ResponseBody 响应 json 数据

1.3.1 使用说明

1.3.2 使用示例

第 2 章 SpringMVC 实现文件上传

2.1 文件上传的回顾

2.1.1 文件上传的必要前提

2.1.2 文件上传的原理分析

2.1.3 借助第三方组件实现文件上传

2.2springmvc 传统方式的文件上传

2.2.1 说明

2.2.2 实现步骤

2.2.2.1 第一步:拷贝文件上传的 jar 包到工程的 lib 目录

2.2.2.2 第二步:编写 jsp 页面

2.2.2.3 第三步:编写控制器

2.2.2.4 第四步:配置文件解析器

2.3springmvc 跨服务器方式的文件上传

2.3.1 分服务器的目的

2.3.2 准备两个 tomcat 服务器,并创建一个用于存放图片的 web 工程

2.3.3 拷贝 jar 包

 

2.3.4 编写控制器实现上传图片

2.3.5 编写 jsp 页面

2.3.6 配置解析器

第 3 章 SpringMVC 中的异常处理

3.1 异常处理的思路

3.2 实现步骤

3.2.1 编写异常类和错误页面

3.2.2 自定义异常处理器

3.2.3 配置异常处理器

3.2.4 运行结果:

第 4 章 SpringMVC 中的拦截器

4.1 拦截器的作用

4.2 自定义拦截器的步骤

4.2.1 第一步:编写一个普通类实现 HandlerInterceptor 接口

4.2.2 第二步:配置拦截器

4.2.3 测试运行结果:

 4.3 拦截器的细节

4.3.1 拦截器的放行

4.3.2 拦截器中方法的说明

4.3.3 拦截器的作用路径

4.3.4 多个拦截器的执行顺序

4.4 正常流程测试

4.4.1 配置文件:

4.4.2 拦截器 1 的代码:

4.4.3 拦截器 2 的代码:

4.4.4 运行结果:

4.5 中断流程测试

4.5.1 配置文件:

4.5.2 拦截器 1 的代码:

4.5.3 拦截器 2 的代码:

4.5.4 运行结果:

4.6 拦截器的简单案例(验证用户是否登录)

4.6.1 实现思路

4.6.2 控制器代码

4.6.3 拦截器代码

 

JavaEE_Mybatis_SpringMVC_SpringMVC_lesson1_简单的SpringMVC框架搭建指南

JavaEE_Mybatis_SpringMVC_SpringMVC_lesson1_简单的SpringMVC框架搭建指南

单独的Spring框架搭建


所需文件

1. SpringMVC框架的包  注意包括JSTL包,SpringMVC需要

如图





2. web.xml 配置文件

里面配置了前端控制器RequestDispatcher,并指定了其他的 处理器Handler,处理器适配器:  处理器映射器  视图解析器的配置文件的地址


3.springmvc.xml 配置文件

 配置了 处理器Handler,处理器适配器:  处理器映射器  视图解析器的配置文件。


4.Handler 的实现类

/SpringMVC_test1/src/cn/itcast/ssm/controller/ItemsController1.java


5.自定义的pojo,(与Mybatis 整合后,由Mybatis 提供),由Mybatis 实现持久层

   为 Items.java


6.前端的JSP 测试页面

/SpringMVC_test1/WebRoot/WEB-INF/jsp/items/itemsList.jsp


整体的文档目录图如下图所示:




注意事项

(1)  web.xml 需要放到WEB-INF目录下的第一级目录,否则不会被加载



2. web.xml 配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SpringMVC_test1</display-name>
  
  <!-- springmvc前端控制器 -->
  <servlet>
  	<servlet-name>springmvc</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	<!-- contextConfigLocation配置springmvc加载的配置文件(配置处理器映射器、适配器等等)
  	如果不配置contextConfigLocation,默认加载的是/WEB-INF/servlet名称-serlvet.xml(springmvc-servlet.xml)
  	 -->
  	<init-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>classpath:springmvc.xml</param-value>
  	</init-param>
  </servlet>
  
  <servlet-mapping>
  	<servlet-name>springmvc</servlet-name>
  	<!--
  	第一种: *.action, 访问以action结尾 由DispatcherServlet进行解析
  	第二种:/,所有的访问地址都由DispatcherServlet进行解析,对于静态文件的解析需要配置不让
  	DispatcherServlet进行解析,使用此方式可以实现RESTful风格的url 
  	第三种: /*,这样配置不对,使用这种配置,最终需要转发到一个jsp页面时,仍然会由
  	DispatcherServlet解析jsp,不能根据jsp页面找到handler,会报错。
  	 -->
  	<url-pattern>*.action</url-pattern>
  </servlet-mapping>
  
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

3.springmvc.xml 配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.2.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">


	<!-- 处理器Handler: 处理器映射器映射的具体的处理器 -->
	<bean name="/queryItems.action" class="cn.itcast.ssm.controller.ItemsController1"/>

	<!-- 处理器适配器:  所有处理器适配器都实现 HandlerAdapter接口 -->
	<bean
		class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

	<!-- 处理器映射器 :	将Bean的 name的 url进行查找,需要在配置Handler指定Beanname(就是url) -->
	<bean
		class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />


	<!-- 视图解析器 -->
	<!-- ViewResolver
	 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	</bean>
</beans>


4.Handler 的实现类

/SpringMVC_test1/src/cn/itcast/ssm/controller/ItemsController1.java

package cn.itcast.ssm.controller;
  • import java.util.ArrayList;
  • import java.util.List;
  • import javax.servlet.http.HttpServletRequest;
  • import javax.servlet.http.HttpServletResponse;
  • import org.springframework.web.servlet.ModelAndView;
  • import org.springframework.web.servlet.mvc.Controller;
  • import cn.itcast.ssm.po.Items;
  • public class ItemsController1 implements Controller {
  • @Override
  • public ModelAndView handleRequest(HttpServletRequest request,
  • HttpServletResponse response) throws Exception {
  • List<Items> itemsList = new ArrayList<>();
  • Items items_1 = new Items();
  • items_1.setName("联想笔记本");
  • items_1.setPrice(6000f);
  • items_1.setDetail("ThinkPad T430 联想笔记本电脑!");
  • Items items_2 = new Items();
  • items_2.setName("苹果手机");
  • items_2.setPrice(5000f);
  • items_2.setDetail("iphone6苹果手机!");
  • itemsList.add(items_1);
  • itemsList.add(items_2);
  • // 返回ModelAndView
  • ModelAndView modelAndView = new ModelAndView();
  • // 相当于request 的 setAttribute, 在 jsp 页面中通过 itemList 取数据
  • modelAndView.addObject("itemsList", itemsList);
  • // 指定视图
  • modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");
  • return modelAndView;
  • }
  • }


  • 5.自定义的pojo,(与Mybatis 整合后,由Mybatis 提供),由Mybatis 实现持久层

       为 Items.java

    1. package cn.itcast.ssm.po;
    2. import java.util.Date;
    3. public class Items {
    4. private Integer id;
    5. private String name;
    6. private Float price;
    7. private String pic;
    8. private Date createtime;
    9. private String detail;
    10. public Integer getId() {
    11. return id;
    12. }
    13. public void setId(Integer id) {
    14. this.id = id;
    15. }
    16. public String getName() {
    17. return name;
    18. }
    19. public void setName(String name) {
    20. this.name = name == null ? null : name.trim();
    21. }
    22. public Float getPrice() {
    23. return price;
    24. }
    25. public void setPrice(Float price) {
    26. this.price = price;
    27. }
    28. public String getPic() {
    29. return pic;
    30. }
    31. public void setPic(String pic) {
    32. this.pic = pic == null ? null : pic.trim();
    33. }
    34. public Date getCreatetime() {
    35. return createtime;
    36. }
    37. public void setCreatetime(Date createtime) {
    38. this.createtime = createtime;
    39. }
    40. public String getDetail() {
    41. return detail;
    42. }
    43. public void setDetail(String detail) {
    44. this.detail = detail == null ? null : detail.trim();
    45. }
    46. }


    6.前端的JSP 测试页面

    /SpringMVC_test1/WebRoot/WEB-INF/jsp/items/itemsList.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>查询商品列表</title>
    </head>
    <body>
    	<form
    		action="${pageContext.request.contextPath }/item/queryItem.action"
    		method="post">
    		查询条件:
    		<table width="100%" border=1>
    			<tr>
    				<td><input type="submit" value="查询" /></td>
    			</tr>
    		</table>
    		商品列表:
    		<table width="100%" border=1>
    			<tr>
    				<td>商品名称</td>
    				<td>商品价格</td>
    				<td>生产日期</td>
    				<td>商品描述</td>
    				<td>操作</td>
    			</tr>
    			<c:forEach items="${itemsList }" var="item">
    				<tr>
    					<td>${item.name }</td>
    					<td>${item.price }</td>
    					<td><fmt:formatDate value="${item.createtime}"
    							pattern="yyyy-MM-dd HH:mm:ss" /></td>
    					<td>${item.detail }</td>
    
    					<td><a
    						href="${pageContext.request.contextPath }/item/editItem.action?id=${item.id}">修改</a></td>
    
    				</tr>
    			</c:forEach>
    
    		</table>
    	</form>
    </body>
    
    </html>

    测试结果:显示


    今天的关于xml 约束写法 -springMvc 参考spring中xml约束有什么用的分享已经结束,谢谢您的关注,如果想了解更多关于19. SpringBoot 扩展 SpringMVC功能、 接管、自定义SpringMVC、applicationContext-mvc.xml(Spring 集成 SpringMVC)配置文件、java day62【 响应数据和结果视图 、 SpringMVC 实现文件上传 、 SpringMVC 中的异常处理 、 SpringMVC 中的拦截器 】、JavaEE_Mybatis_SpringMVC_SpringMVC_lesson1_简单的SpringMVC框架搭建指南的相关知识,请在本站进行查询。

    本文标签:

    上一篇cookie和session的跟踪过程(cookie与session联系)

    下一篇springmvc mybatis 调用sql , 转成json(mybatis plus json转对象)