Commit be5e30b4 authored by Stephane Nicoll's avatar Stephane Nicoll

Migrate spring.view properties

Migrate `spring.view.prefix` and `spring.view.suffix` to
`spring.mvc.view.prefix` and `spring.mvc.view.suffix` respectively. The
former properties are still handled in a backward compatible way and are
defined as deprecated in the meta-data.

Closes gh-3250
parent 77f303b4
......@@ -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;
}
}
......@@ -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;
}
......
......@@ -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;
}
}
}
......@@ -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
}
]}
......@@ -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
......
......@@ -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
......
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
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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment