From 4c0d03f8e10c0171590f20b1089a6d292baeb6fe Mon Sep 17 00:00:00 2001 From: Timothy Hobbs Date: Sat, 10 Dec 2022 19:39:18 +0100 Subject: [PATCH] Add SpringConfig.java fixes #1 --- .../java/com/mkyong/web/SpringConfig.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 java-web-project/src/main/java/com/mkyong/web/SpringConfig.java diff --git a/java-web-project/src/main/java/com/mkyong/web/SpringConfig.java b/java-web-project/src/main/java/com/mkyong/web/SpringConfig.java new file mode 100644 index 0000000..ba7f05a --- /dev/null +++ b/java-web-project/src/main/java/com/mkyong/web/SpringConfig.java @@ -0,0 +1,33 @@ + +package com.mkyong.web.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.view.InternalResourceViewResolver; +import org.springframework.web.servlet.view.JstlView; + +@EnableWebMvc +@Configuration +@ComponentScan({"com.mkyong.web"}) +public class SpringConfig implements WebMvcConfigurer { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**") + .addResourceLocations("/resources/"); + } + + @Bean + public InternalResourceViewResolver viewResolver() { + InternalResourceViewResolver viewResolver + = new InternalResourceViewResolver(); + viewResolver.setViewClass(JstlView.class); + viewResolver.setPrefix("/WEB-INF/views/"); + viewResolver.setSuffix(".jsp"); + return viewResolver; + } +}