MvcDefaultServletHandler.java 3.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright 2002-2011 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;

C
Chris Beams 已提交
18
import org.springframework.beans.factory.parsing.ProblemCollector;
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
import org.springframework.context.config.AbstractFeatureSpecification;
import org.springframework.context.config.FeatureSpecificationExecutor;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
import org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler;

/**
 * Specifies the Spring MVC "default-servlet-handler" container feature. The
 * feature provides the following fine-grained configuration:
 *
 * <ul>
 * 	<li>{@link DefaultServletHttpRequestHandler} for serving static files by 
 * 		forwarding to the Servlet container's "default" Servlet. 
 * 	<li>{@link SimpleUrlHandlerMapping} to map the above request handler to "/**"
 * 	<li>{@link HttpRequestHandlerAdapter} to enable the DispatcherServlet to be
 *     able to invoke the above request handler.
 * </ul>
36 37 38 39 40 41 42
 *
 * This handler will forward all requests to the default Servlet. Therefore 
 * it is important that it remains last in the order of all other URL 
 * HandlerMappings. That will be the case if you use the {@link MvcAnnotationDriven} 
 * feature or alternatively if you are setting up your customized HandlerMapping 
 * instance be sure to set its "order" property to a value lower than that of 
 * the DefaultServletHttpRequestHandler, which is Integer.MAX_VALUE. 
43 44 45 46
 * 
 * @author Rossen Stoyanchev
 * @since 3.1
 */
C
Chris Beams 已提交
47
public final class MvcDefaultServletHandler extends AbstractFeatureSpecification {
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

	private static final Class<? extends FeatureSpecificationExecutor> EXECUTOR_TYPE = MvcDefaultServletHandlerExecutor.class;

	private String defaultServletName;

	/**
	 * <p>Creates an instance of MvcDefaultServletHandler without.
	 * If this constructor is used the {@link DefaultServletHttpRequestHandler} 
	 * will try to auto-detect the container's default Servlet at startup time 
	 * using a list of known names.
	 *   
	 * <p>If the default Servlet cannot be detected because of using an 
	 * unknown container or because it has been manually configured, an 
	 * alternate constructor provided here can be used to specify the 
	 * servlet name explicitly.
	 */
	public MvcDefaultServletHandler() {
		super(EXECUTOR_TYPE);
	}

	/**
	 * The name of the default Servlet to forward to for static resource requests.  
	 * The {@link DefaultServletHttpRequestHandler} will try to auto-detect the 
	 * container's default Servlet at startup time using a list of known names.  
	 * However if the default Servlet cannot be detected because of using an unknown 
	 * container or because it has been manually configured, you can use this 
	 * constructor to set the servlet name explicitly.
	 * 
	 * @param defaultServletName the name of the default servlet
	 */
	public MvcDefaultServletHandler(String defaultServletName) {
		this();
		this.defaultServletName = defaultServletName;
	}

	String defaultServletName() {
		return this.defaultServletName;
	}

	@Override
C
Chris Beams 已提交
88
	protected void doValidate(ProblemCollector problems) {
89 90 91
	}

}