From 3fce5f424d492d1003bc16485d55dd3caa7092e1 Mon Sep 17 00:00:00 2001 From: Shashank Date: Sat, 2 Oct 2021 21:33:59 +0530 Subject: [PATCH] feat: removing deprecated view resolver classes and configuring BeanNameViewResolver --- spring-web-modules/spring-mvc-basics/pom.xml | 1 - .../baeldung/spring/web/config/WebConfig.java | 35 +++++++++++-------- .../src/main/resources/views.properties | 3 -- .../src/main/resources/views.xml | 10 ------ 4 files changed, 20 insertions(+), 29 deletions(-) delete mode 100644 spring-web-modules/spring-mvc-basics/src/main/resources/views.properties delete mode 100644 spring-web-modules/spring-mvc-basics/src/main/resources/views.xml diff --git a/spring-web-modules/spring-mvc-basics/pom.xml b/spring-web-modules/spring-mvc-basics/pom.xml index 9fe4494393..a91f4004ff 100644 --- a/spring-web-modules/spring-mvc-basics/pom.xml +++ b/spring-web-modules/spring-mvc-basics/pom.xml @@ -33,7 +33,6 @@ org.apache.tomcat.embed tomcat-embed-jasper - provided javax.servlet diff --git a/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java index ac917018b0..e1987f8345 100644 --- a/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -1,13 +1,11 @@ package com.baeldung.spring.web.config; -import java.io.IOException; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; import org.springframework.http.MediaType; import org.springframework.ui.context.support.ResourceBundleThemeSource; import org.springframework.web.multipart.commons.CommonsMultipartResolver; +import org.springframework.web.servlet.View; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; 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.theme.CookieThemeResolver; 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.JstlView; -import org.springframework.web.servlet.view.ResourceBundleViewResolver; -import org.springframework.web.servlet.view.XmlViewResolver; + +import java.io.IOException; //@EnableWebMvc //@ComponentScan(basePackages = { "com.baeldung.web.controller" }) @@ -93,19 +92,25 @@ public class WebConfig implements WebMvcConfigurer { /** END theme configuration */ @Bean - public ViewResolver resourceBundleViewResolver() { - final ResourceBundleViewResolver bean = new ResourceBundleViewResolver(); - bean.setBasename("views"); - bean.setOrder(0); - return bean; + public BeanNameViewResolver beanNameViewResolver(){ + BeanNameViewResolver beanNameViewResolver = new BeanNameViewResolver(); + beanNameViewResolver.setOrder(1); + return beanNameViewResolver; } @Bean - public ViewResolver xmlViewResolver() { - final XmlViewResolver bean = new XmlViewResolver(); - bean.setLocation(new ClassPathResource("views.xml")); - bean.setOrder(1); - return bean; + public View sample() { + return new JstlView("/WEB-INF/view/sample.jsp"); + } + + @Bean + public View sample2() { + return new JstlView("/WEB-INF/view2/sample2.jsp"); + } + + @Bean + public View sample3(){ + return new JstlView("/WEB-INF/view3/sample3.jsp"); } /** diff --git a/spring-web-modules/spring-mvc-basics/src/main/resources/views.properties b/spring-web-modules/spring-mvc-basics/src/main/resources/views.properties deleted file mode 100644 index 06d042b446..0000000000 --- a/spring-web-modules/spring-mvc-basics/src/main/resources/views.properties +++ /dev/null @@ -1,3 +0,0 @@ -sample2.(class)=org.springframework.web.servlet.view.JstlView -sample2.url=/WEB-INF/view2/sample2.jsp - diff --git a/spring-web-modules/spring-mvc-basics/src/main/resources/views.xml b/spring-web-modules/spring-mvc-basics/src/main/resources/views.xml deleted file mode 100644 index a44d3deae4..0000000000 --- a/spring-web-modules/spring-mvc-basics/src/main/resources/views.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - \ No newline at end of file