diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/JspTemplateAvailabilityProvider.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/JspTemplateAvailabilityProvider.java index 2193231fb54..da111144f66 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/JspTemplateAvailabilityProvider.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/JspTemplateAvailabilityProvider.java @@ -26,6 +26,7 @@ import org.springframework.util.ClassUtils; * view templates * * @author Andy Wilkinson + * @author Stephane Nicoll * @since 1.1.0 */ public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProvider { @@ -34,13 +35,23 @@ public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProv public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) { if (ClassUtils.isPresent("org.apache.jasper.compiler.JspConfig", classLoader)) { - String prefix = environment.getProperty("spring.view.prefix", + String prefix = getProperty(environment, "spring.mvc.view.prefix", "spring.view.prefix", WebMvcAutoConfiguration.DEFAULT_PREFIX); - String suffix = environment.getProperty("spring.view.suffix", + String suffix = getProperty(environment, "spring.mvc.view.suffix", "spring.view.suffix", WebMvcAutoConfiguration.DEFAULT_SUFFIX); return resourceLoader.getResource(prefix + view + suffix).exists(); } return false; } + private String getProperty(Environment environment, String key, String deprecatedKey, String defaultValue) { + if (environment.containsProperty(key)) { + return environment.getProperty(key); + } + if (environment.containsProperty(deprecatedKey)) { + return environment.getProperty(deprecatedKey); + } + return defaultValue; + } + } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index 28111456827..3968cd6108b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -30,7 +30,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureOrder; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -142,12 +141,6 @@ public class WebMvcAutoConfiguration { private static Log logger = LogFactory.getLog(WebMvcConfigurerAdapter.class); - @Value("${spring.view.prefix:}") - private String prefix = ""; - - @Value("${spring.view.suffix:}") - private String suffix = ""; - @Autowired private ResourceProperties resourceProperties = new ResourceProperties(); @@ -180,8 +173,8 @@ public class WebMvcAutoConfiguration { @ConditionalOnMissingBean(InternalResourceViewResolver.class) public InternalResourceViewResolver defaultViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); - resolver.setPrefix(this.prefix); - resolver.setSuffix(this.suffix); + resolver.setPrefix(this.mvcProperties.getView().getPrefix()); + resolver.setSuffix(this.mvcProperties.getView().getSuffix()); return resolver; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java index e841dc2f249..34180b1681b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.web; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.DefaultMessageCodesResolver; @@ -24,6 +25,7 @@ import org.springframework.validation.DefaultMessageCodesResolver; * * @author Phillip Webb * @author Sébastien Deleuze + * @author Stephane Nicoll * @since 1.1 */ @ConfigurationProperties("spring.mvc") @@ -52,6 +54,8 @@ public class WebMvcProperties { private final Async async = new Async(); + private final View view = new View(); + public DefaultMessageCodesResolver.Format getMessageCodesResolverFormat() { return this.messageCodesResolverFormat; } @@ -89,6 +93,10 @@ public class WebMvcProperties { return this.async; } + public View getView() { + return this.view; + } + public static class Async { /** @@ -107,4 +115,35 @@ public class WebMvcProperties { } } + + public static class View { + + /** + * Spring MVC view prefix. + */ + @Value("${spring.view.prefix:}") + private String prefix; + + /** + * Spring MVC view suffx. + */ + @Value("${spring.view.suffix:}") + private String suffix; + + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } + } } diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 1b0b8e1630f..4b2b51bc522 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -149,12 +149,14 @@ { "name": "spring.view.prefix", "type": "java.lang.String", - "description": "Spring MVC view prefix." + "description": "Spring MVC view prefix.", + "deprecated": true }, { "name": "spring.view.suffix", "type": "java.lang.String", - "description": "Spring MVC view suffix." + "description": "Spring MVC view suffix.", + "deprecated": true } ]} diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 20222975158..be57aea4b7e 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -122,8 +122,8 @@ content into your application; rather pick only the properties that you need. spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE spring.mvc.ignore-default-model-on-redirect=true # if the the content of the "default" model should be ignored redirects spring.mvc.async.request-timeout= # async request timeout in milliseconds - spring.view.prefix= # MVC view prefix - spring.view.suffix= # ... and suffix + spring.mvc.view.prefix= # MVC view prefix + spring.mvc.view.suffix= # ... and suffix # SPRING RESOURCES HANDLING ({sc-spring-boot-autoconfigure}/web/ResourceProperties.{sc-ext}[ResourceProperties]) spring.resources.cache-period= # cache timeouts in headers sent to browser diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 6540890be2e..3c7299e14ab 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1110,7 +1110,7 @@ added. resources and JSP pages if you are using those). It applies a prefix and a suffix to the view name and then looks for a physical resource with that path in the servlet context (defaults are both empty, but accessible for external configuration via - `spring.view.prefix` and `spring.view.suffix`). It can be overridden by providing a + `spring.mvc.view.prefix` and `spring.mvc.view.suffix`). It can be overridden by providing a bean of the same type. * A `BeanNameViewResolver` with id '`beanNameViewResolver`'. This is a useful member of the view resolver chain and will pick up any beans with the same name as the `View` being diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/application.properties index f95f1d3c014..2af7f6e200d 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/application.properties @@ -1,3 +1,3 @@ -spring.view.prefix: /WEB-INF/jsp/ -spring.view.suffix: .jsp +spring.mvc.view.prefix: /WEB-INF/jsp/ +spring.mvc.view.suffix: .jsp application.message: Hello Phil \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/main/resources/application.properties index f95f1d3c014..2af7f6e200d 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/main/resources/application.properties @@ -1,3 +1,3 @@ -spring.view.prefix: /WEB-INF/jsp/ -spring.view.suffix: .jsp +spring.mvc.view.prefix: /WEB-INF/jsp/ +spring.mvc.view.suffix: .jsp application.message: Hello Phil \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-web-jsp/src/main/resources/application.properties index f95f1d3c014..2af7f6e200d 100644 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-web-jsp/src/main/resources/application.properties @@ -1,3 +1,3 @@ -spring.view.prefix: /WEB-INF/jsp/ -spring.view.suffix: .jsp +spring.mvc.view.prefix: /WEB-INF/jsp/ +spring.mvc.view.suffix: .jsp application.message: Hello Phil \ No newline at end of file