Add spring.view.{prefix,suffix} properties

Fixes #62
This commit is contained in:
Dave Syer 2013-09-27 09:34:10 -04:00
parent c661a74c75
commit 923f286ae2
3 changed files with 12 additions and 12 deletions

View File

@ -28,6 +28,7 @@ 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.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@ -110,6 +111,12 @@ 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 ListableBeanFactory beanFactory;
@ -117,10 +124,11 @@ public class WebMvcAutoConfiguration {
private ResourceLoader resourceLoader;
@Bean
@ConditionalOnBean(View.class)
@ConditionalOnMissingBean(InternalResourceViewResolver.class)
public InternalResourceViewResolver defaultViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix(this.prefix);
resolver.setSuffix(this.suffix);
return resolver;
}

View File

@ -18,24 +18,14 @@ package org.springframework.boot.sample.jsp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SampleWebJspApplication {
@Bean
public InternalResourceViewResolver defaultViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebJspApplication.class, args);
}

View File

@ -0,0 +1,2 @@
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp