From 4f77aa59cd6acbf3c82f771d73d4c96165f542e3 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 28 Jul 2019 10:50:15 +0530 Subject: [PATCH] [BAEL-15393] - Initial commit to change to boot 2 --- spring-mvc-java/pom.xml | 37 +++++++++++-------- .../com/baeldung/SpringMVCApplication.java | 11 ++++++ .../baeldung/spring/web/config/WebConfig.java | 13 ++----- .../src/main/resources/application.properties | 21 +++++++++++ 4 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java create mode 100644 spring-mvc-java/src/main/resources/application.properties diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index cb16e91bc4..da9bd04d3d 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -8,17 +8,24 @@ war - parent-spring-5 + parent-boot-2 com.baeldung 0.0.1-SNAPSHOT - ../parent-spring-5 + ../parent-boot-2 - org.springframework - spring-webmvc - ${spring.version} + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-jdbc javax.servlet @@ -106,9 +113,8 @@ 2.4.0 - org.springframework - spring-test - ${spring.version} + org.springframework.boot + spring-boot-starter-test test @@ -134,16 +140,15 @@ 2.8.5 - org.springframework - spring-websocket - ${spring.version} + org.springframework.boot + spring-boot-starter-websocket - - org.springframework - spring-messaging - ${spring.version} - + + + + + org.glassfish javax.el diff --git a/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java b/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java new file mode 100644 index 0000000000..ee263aaab2 --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/SpringMVCApplication.java @@ -0,0 +1,11 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringMVCApplication { + public static void main(String[] args) { + SpringApplication.run(SpringMVCApplication.class, args); + } +} \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java index 44fef92917..7aa9d6c5b5 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -3,9 +3,6 @@ package com.baeldung.spring.web.config; import java.util.ArrayList; import java.util.List; -import javax.servlet.ServletContext; - -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -26,8 +23,9 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.util.UrlPathHelper; import org.thymeleaf.spring4.SpringTemplateEngine; +import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver; import org.thymeleaf.spring4.view.ThymeleafViewResolver; -import org.thymeleaf.templateresolver.ServletContextTemplateResolver; +import org.thymeleaf.templateresolver.ITemplateResolver; import com.baeldung.excel.ExcelPOIHelper; @@ -35,9 +33,6 @@ import com.baeldung.excel.ExcelPOIHelper; @Configuration @ComponentScan(basePackages = { "com.baeldung.web.controller" }) public class WebConfig implements WebMvcConfigurer { - - @Autowired - private ServletContext ctx; @Override public void addViewControllers(final ViewControllerRegistry registry) { @@ -64,8 +59,8 @@ public class WebConfig implements WebMvcConfigurer { @Bean @Description("Thymeleaf template resolver serving HTML 5") - public ServletContextTemplateResolver templateResolver() { - final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx); + public ITemplateResolver templateResolver() { + final SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); templateResolver.setPrefix("/WEB-INF/templates/"); templateResolver.setSuffix(".html"); templateResolver.setTemplateMode("HTML5"); diff --git a/spring-mvc-java/src/main/resources/application.properties b/spring-mvc-java/src/main/resources/application.properties new file mode 100644 index 0000000000..4f618c96a9 --- /dev/null +++ b/spring-mvc-java/src/main/resources/application.properties @@ -0,0 +1,21 @@ +spring.servlet.multipart.max-file-size=10MB +spring.servlet.multipart.max-request-size=10MB +spring.http.multipart.enabled=true +spring.servlet.multipart.location=${java.io.tmpdir} + +logging.level.org.springframework=DEBUG +logging.level.com.baeldung=DEBUG + +#output to a temp_folder/file +logging.file=${java.io.tmpdir}/application.log + +# Logging pattern for the console +logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} - %msg%n + +# Logging pattern for file +logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg% +spring.http.encoding.charset=UTF-8 +# Enable http encoding support. +spring.http.encoding.enabled=true +# Force the encoding to the configured charset on HTTP requests and responses. +spring.http.encoding.force=true \ No newline at end of file