From 78ca924a13817c591603ff00dddca7b370e587e8 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Fri, 6 Sep 2019 01:31:18 +0530 Subject: [PATCH] [BAEL-15393] - Update Spring File Upload article --- spring-mvc-java/pom.xml | 31 +++---------------- .../java/com/baeldung/aop/LoggingAspect.java | 6 ++-- .../com/baeldung/aop/PerformanceAspect.java | 2 +- .../com/baeldung/aop/PublishingAspect.java | 4 +-- .../baeldung/spring/web/config/WebConfig.java | 12 +------ .../src/main/resources/application.properties | 26 +++------------- 6 files changed, 17 insertions(+), 64 deletions(-) diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index da9bd04d3d..87d2f612af 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -19,14 +19,6 @@ org.springframework.boot spring-boot-starter-web - - org.springframework.boot - spring-boot-starter-tomcat - - - org.springframework.boot - spring-boot-starter-jdbc - javax.servlet javax.servlet-api @@ -40,7 +32,11 @@ javax.servlet jstl - ${jstl.version} + + + org.apache.tomcat.embed + tomcat-embed-jasper + provided @@ -62,17 +58,6 @@ - - commons-fileupload - commons-fileupload - ${commons-fileupload.version} - - - commons-io - commons-io - - - net.sourceforge.htmlunit htmlunit @@ -143,12 +128,6 @@ org.springframework.boot spring-boot-starter-websocket - - - - - - org.glassfish javax.el diff --git a/spring-mvc-java/src/main/java/com/baeldung/aop/LoggingAspect.java b/spring-mvc-java/src/main/java/com/baeldung/aop/LoggingAspect.java index 7ae37404be..169d664471 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/aop/LoggingAspect.java +++ b/spring-mvc-java/src/main/java/com/baeldung/aop/LoggingAspect.java @@ -23,15 +23,15 @@ public class LoggingAspect { } }; - @Pointcut("@target(org.springframework.stereotype.Repository)") + @Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))") public void repositoryMethods() { } - @Pointcut("@annotation(com.baeldung.aop.annotations.Loggable)") + @Pointcut("within(com.baeldung..*) && @annotation(com.baeldung.aop.annotations.Loggable)") public void loggableMethods() { } - @Pointcut("@args(com.baeldung.aop.annotations.Entity)") + @Pointcut("within(com.baeldung..*) && @args(com.baeldung.aop.annotations.Entity)") public void methodsAcceptingEntities() { } diff --git a/spring-mvc-java/src/main/java/com/baeldung/aop/PerformanceAspect.java b/spring-mvc-java/src/main/java/com/baeldung/aop/PerformanceAspect.java index 1f2076adff..8f374cc1e5 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/aop/PerformanceAspect.java +++ b/spring-mvc-java/src/main/java/com/baeldung/aop/PerformanceAspect.java @@ -15,7 +15,7 @@ public class PerformanceAspect { private static Logger logger = Logger.getLogger(PerformanceAspect.class.getName()); - @Pointcut("within(@org.springframework.stereotype.Repository *)") + @Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))") public void repositoryClassMethods() { } diff --git a/spring-mvc-java/src/main/java/com/baeldung/aop/PublishingAspect.java b/spring-mvc-java/src/main/java/com/baeldung/aop/PublishingAspect.java index 7791c63e7b..a45402dc18 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/aop/PublishingAspect.java +++ b/spring-mvc-java/src/main/java/com/baeldung/aop/PublishingAspect.java @@ -20,11 +20,11 @@ public class PublishingAspect { this.eventPublisher = eventPublisher; } - @Pointcut("@target(org.springframework.stereotype.Repository)") + @Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))") public void repositoryMethods() { } - @Pointcut("execution(* *..create*(Long,..))") + @Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.create*(Long,..))") public void firstLongParamMethods() { } 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 7aa9d6c5b5..96e300464b 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 @@ -12,7 +12,6 @@ import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.http.MediaType; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; @@ -63,7 +62,7 @@ public class WebConfig implements WebMvcConfigurer { final SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); templateResolver.setPrefix("/WEB-INF/templates/"); templateResolver.setSuffix(".html"); - templateResolver.setTemplateMode("HTML5"); + templateResolver.setTemplateMode("HTML"); return templateResolver; } @@ -87,15 +86,6 @@ public class WebConfig implements WebMvcConfigurer { public void addResourceHandlers(final ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); } - - @Bean(name = "multipartResolver") - public CommonsMultipartResolver multipartResolver() { - - final CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(); - multipartResolver.setMaxUploadSize(100000); - - return multipartResolver; - } @Override public void extendMessageConverters(final List> converters) { diff --git a/spring-mvc-java/src/main/resources/application.properties b/spring-mvc-java/src/main/resources/application.properties index 4f618c96a9..00c491c271 100644 --- a/spring-mvc-java/src/main/resources/application.properties +++ b/spring-mvc-java/src/main/resources/application.properties @@ -1,21 +1,5 @@ -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 +server.servlet.context-path=/spring-mvc-java +spring.servlet.multipart.max-file-size=1MB +spring.servlet.multipart.max-request-size=1MB +spring.servlet.multipart.enabled=true +spring.servlet.multipart.location=${java.io.tmpdir} \ No newline at end of file