parent
08c85c1fba
commit
cc855f4462
|
@ -48,6 +48,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
||||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
|
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders;
|
||||||
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
|
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
|
||||||
import org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain;
|
import org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain;
|
||||||
|
@ -57,6 +58,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||||
import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter;
|
import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter;
|
||||||
import org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter;
|
import org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter;
|
||||||
import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter;
|
import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ResourceLoaderAware;
|
import org.springframework.context.ResourceLoaderAware;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -130,6 +132,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Kristine Jetzke
|
* @author Kristine Jetzke
|
||||||
|
* @author Bruce Brouwer
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnWebApplication(type = Type.SERVLET)
|
@ConditionalOnWebApplication(type = Type.SERVLET)
|
||||||
|
@ -330,8 +333,11 @@ public class WebMvcAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public WelcomePageHandlerMapping welcomePageHandlerMapping() {
|
public WelcomePageHandlerMapping welcomePageHandlerMapping(
|
||||||
return new WelcomePageHandlerMapping(getWelcomePage(),
|
ApplicationContext applicationContext) {
|
||||||
|
return new WelcomePageHandlerMapping(
|
||||||
|
new TemplateAvailabilityProviders(applicationContext),
|
||||||
|
applicationContext, getWelcomePage(),
|
||||||
this.mvcProperties.getStaticPathPattern());
|
this.mvcProperties.getStaticPathPattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
@ -37,20 +39,38 @@ import org.springframework.web.servlet.mvc.ParameterizableViewController;
|
||||||
* static page is preferred.
|
* static page is preferred.
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Bruce Brouwer
|
||||||
*/
|
*/
|
||||||
final class WelcomePageHandlerMapping extends AbstractUrlHandlerMapping {
|
final class WelcomePageHandlerMapping extends AbstractUrlHandlerMapping {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(WelcomePageHandlerMapping.class);
|
private static final Log logger = LogFactory.getLog(WelcomePageHandlerMapping.class);
|
||||||
|
|
||||||
WelcomePageHandlerMapping(Optional<Resource> welcomePage, String staticPathPattern) {
|
WelcomePageHandlerMapping(TemplateAvailabilityProviders templateAvailabilityProviders,
|
||||||
if (welcomePage.isPresent() && "/**".equals(staticPathPattern)) {
|
ApplicationContext applicationContext, Optional<Resource> welcomePage,
|
||||||
logger.info("Adding welcome page: " + welcomePage.get());
|
String staticPathPattern) {
|
||||||
|
if (welcomeTemplateExists(templateAvailabilityProviders, applicationContext)) {
|
||||||
|
logger.info("Adding welcome page template: index");
|
||||||
|
setRootViewName("index");
|
||||||
|
}
|
||||||
|
else if (welcomePage.isPresent() && "/**".equals(staticPathPattern)) {
|
||||||
|
logger.info("Adding welcome page: " + welcomePage);
|
||||||
|
setRootViewName("forward:index.html");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean welcomeTemplateExists(
|
||||||
|
TemplateAvailabilityProviders templateAvailabilityProviders,
|
||||||
|
ApplicationContext applicationContext) {
|
||||||
|
return templateAvailabilityProviders.getProvider("index",
|
||||||
|
applicationContext) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRootViewName(final String viewName) {
|
||||||
ParameterizableViewController controller = new ParameterizableViewController();
|
ParameterizableViewController controller = new ParameterizableViewController();
|
||||||
controller.setViewName("forward:index.html");
|
controller.setViewName(viewName);
|
||||||
setRootHandler(controller);
|
setRootHandler(controller);
|
||||||
setOrder(0);
|
setOrder(0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getHandlerInternal(HttpServletRequest request) throws Exception {
|
public Object getHandlerInternal(HttpServletRequest request) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue