feat: removing deprecated view resolver classes and configuring BeanNameViewResolver
This commit is contained in:
parent
be966d6d62
commit
3fce5f424d
|
@ -33,7 +33,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.tomcat.embed</groupId>
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
<artifactId>tomcat-embed-jasper</artifactId>
|
<artifactId>tomcat-embed-jasper</artifactId>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package com.baeldung.spring.web.config;
|
package com.baeldung.spring.web.config;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.ui.context.support.ResourceBundleThemeSource;
|
import org.springframework.ui.context.support.ResourceBundleThemeSource;
|
||||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||||
|
import org.springframework.web.servlet.View;
|
||||||
import org.springframework.web.servlet.ViewResolver;
|
import org.springframework.web.servlet.ViewResolver;
|
||||||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
@ -17,10 +15,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
import org.springframework.web.servlet.resource.PathResourceResolver;
|
import org.springframework.web.servlet.resource.PathResourceResolver;
|
||||||
import org.springframework.web.servlet.theme.CookieThemeResolver;
|
import org.springframework.web.servlet.theme.CookieThemeResolver;
|
||||||
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
|
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
|
||||||
|
import org.springframework.web.servlet.view.BeanNameViewResolver;
|
||||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||||
import org.springframework.web.servlet.view.JstlView;
|
import org.springframework.web.servlet.view.JstlView;
|
||||||
import org.springframework.web.servlet.view.ResourceBundleViewResolver;
|
|
||||||
import org.springframework.web.servlet.view.XmlViewResolver;
|
import java.io.IOException;
|
||||||
|
|
||||||
//@EnableWebMvc
|
//@EnableWebMvc
|
||||||
//@ComponentScan(basePackages = { "com.baeldung.web.controller" })
|
//@ComponentScan(basePackages = { "com.baeldung.web.controller" })
|
||||||
|
@ -93,19 +92,25 @@ public class WebConfig implements WebMvcConfigurer {
|
||||||
/** END theme configuration */
|
/** END theme configuration */
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ViewResolver resourceBundleViewResolver() {
|
public BeanNameViewResolver beanNameViewResolver(){
|
||||||
final ResourceBundleViewResolver bean = new ResourceBundleViewResolver();
|
BeanNameViewResolver beanNameViewResolver = new BeanNameViewResolver();
|
||||||
bean.setBasename("views");
|
beanNameViewResolver.setOrder(1);
|
||||||
bean.setOrder(0);
|
return beanNameViewResolver;
|
||||||
return bean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ViewResolver xmlViewResolver() {
|
public View sample() {
|
||||||
final XmlViewResolver bean = new XmlViewResolver();
|
return new JstlView("/WEB-INF/view/sample.jsp");
|
||||||
bean.setLocation(new ClassPathResource("views.xml"));
|
}
|
||||||
bean.setOrder(1);
|
|
||||||
return bean;
|
@Bean
|
||||||
|
public View sample2() {
|
||||||
|
return new JstlView("/WEB-INF/view2/sample2.jsp");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public View sample3(){
|
||||||
|
return new JstlView("/WEB-INF/view3/sample3.jsp");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
sample2.(class)=org.springframework.web.servlet.view.JstlView
|
|
||||||
sample2.url=/WEB-INF/view2/sample2.jsp
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
|
|
||||||
|
|
||||||
<bean id="sample3" class="org.springframework.web.servlet.view.JstlView">
|
|
||||||
<property name="url" value="/WEB-INF/view3/sample3.jsp" />
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
</beans>
|
|
Loading…
Reference in New Issue