Java Code Examples for org.springframework.web.servlet.resource.ResourceHttpRequestHandler#afterPropertiesSet()

The following examples show how to use org.springframework.web.servlet.resource.ResourceHttpRequestHandler#afterPropertiesSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceHandlerRegistry.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case
 * of no registrations.
 */
@Nullable
protected AbstractHandlerMapping getHandlerMapping() {
	if (this.registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			if (this.pathHelper != null) {
				handler.setUrlPathHelper(this.pathHelper);
			}
			if (this.contentNegotiationManager != null) {
				handler.setContentNegotiationManager(this.contentNegotiationManager);
			}
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.applicationContext);
			try {
				handler.afterPropertiesSet();
			}
			catch (Throwable ex) {
				throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
			}
			urlMap.put(pathPattern, handler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(this.order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
Example 2
Source File: ResourceHandlerRegistry.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case
 * of no registrations.
 */
@Nullable
protected AbstractHandlerMapping getHandlerMapping() {
	if (this.registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			if (this.pathHelper != null) {
				handler.setUrlPathHelper(this.pathHelper);
			}
			if (this.contentNegotiationManager != null) {
				handler.setContentNegotiationManager(this.contentNegotiationManager);
			}
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.applicationContext);
			try {
				handler.afterPropertiesSet();
			}
			catch (Throwable ex) {
				throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
			}
			urlMap.put(pathPattern, handler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(this.order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
Example 3
Source File: ResourceHandlerRegistry.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case
 * of no registrations.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (this.registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.applicationContext);
			handler.setContentNegotiationManager(this.contentNegotiationManager);
			try {
				handler.afterPropertiesSet();
			}
			catch (Throwable ex) {
				throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
			}
			urlMap.put(pathPattern, handler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
Example 4
Source File: ResourceHandlerRegistry.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case of no registrations.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.appContext);
			try {
				handler.afterPropertiesSet();
			}
			catch (Exception e) {
				throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", e);
			}
			urlMap.put(pathPattern, handler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}