Skip to content

Commit 44eca5b

Browse files
committed
Merge branch 'master' of https://github.com/ivanp81/tutorials into ivanp81-master
2 parents 08c8d82 + 3061fc7 commit 44eca5b

14 files changed

Lines changed: 429 additions & 143 deletions

File tree

‎spring-mvc-java/.classpath‎

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="src" output="target/classes" path="src/main/java">
4-
<attributes>
5-
<attribute name="optional" value="true"/>
6-
<attribute name="maven.pomderived" value="true"/>
7-
</attributes>
8-
</classpathentry>
9-
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10-
<attributes>
11-
<attribute name="optional" value="true"/>
12-
<attribute name="maven.pomderived" value="true"/>
13-
</attributes>
14-
</classpathentry>
15-
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
16-
<attributes>
17-
<attribute name="maven.pomderived" value="true"/>
18-
</attributes>
19-
</classpathentry>
20-
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21-
<attributes>
22-
<attribute name="maven.pomderived" value="true"/>
23-
</attributes>
24-
</classpathentry>
25-
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
26-
<attributes>
27-
<attribute name="maven.pomderived" value="true"/>
28-
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
29-
</attributes>
30-
</classpathentry>
31-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
32-
<attributes>
33-
<attribute name="maven.pomderived" value="true"/>
34-
</attributes>
35-
</classpathentry>
36-
<classpathentry kind="output" path="target/classes"/>
37-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
16+
<attributes>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
29+
</attributes>
30+
</classpathentry>
31+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
32+
<attributes>
33+
<attribute name="maven.pomderived" value="true"/>
34+
</attributes>
35+
</classpathentry>
36+
<classpathentry kind="output" path="target/classes"/>
37+
</classpath>

‎spring-mvc-java/pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
<artifactId>slf4j-log4j12</artifactId>
5858
<version>${org.slf4j.version}</version>
5959
</dependency>
60+
<!-- common -->
61+
<dependency>
62+
<groupId>commons-fileupload</groupId>
63+
<artifactId>commons-fileupload</artifactId>
64+
<version>1.3.1</version>
65+
</dependency>
66+
6067
<!-- test scoped -->
6168
<dependency>
6269
<groupId>junit</groupId>

‎spring-mvc-java/src/main/java/org/baeldung/spring/web/config/ClientWebConfig.java‎

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,69 +25,69 @@
2525
@Configuration
2626
public class ClientWebConfig extends WebMvcConfigurerAdapter {
2727

28-
public ClientWebConfig() {
29-
super();
30-
}
28+
public ClientWebConfig() {
29+
super();
30+
}
3131

32-
// API
32+
// API
3333

34-
@Override
35-
public void addViewControllers(final ViewControllerRegistry registry) {
36-
super.addViewControllers(registry);
34+
@Override
35+
public void addViewControllers(final ViewControllerRegistry registry) {
36+
super.addViewControllers(registry);
3737

38-
registry.addViewController("/sample.html");
39-
}
38+
registry.addViewController("/sample.html");
39+
}
4040

41-
@Bean
42-
public ViewResolver thymeleafViewResolver() {
43-
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
44-
viewResolver.setTemplateEngine(templateEngine());
45-
viewResolver.setOrder(1);
46-
return viewResolver;
47-
}
41+
@Bean
42+
public ViewResolver thymeleafViewResolver() {
43+
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
44+
viewResolver.setTemplateEngine(templateEngine());
45+
viewResolver.setOrder(1);
46+
return viewResolver;
47+
}
4848

49-
@Bean
50-
public ViewResolver viewResolver() {
51-
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
52-
bean.setViewClass(JstlView.class);
53-
bean.setPrefix("/WEB-INF/view/");
54-
bean.setSuffix(".jsp");
55-
bean.setOrder(0);
56-
return bean;
57-
}
49+
@Bean
50+
public ViewResolver viewResolver() {
51+
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
52+
bean.setViewClass(JstlView.class);
53+
bean.setPrefix("/WEB-INF/view/");
54+
bean.setSuffix(".jsp");
55+
bean.setOrder(0);
56+
return bean;
57+
}
5858

59-
@Bean
60-
@Description("Thymeleaf template resolver serving HTML 5")
61-
public ServletContextTemplateResolver templateResolver() {
62-
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
63-
templateResolver.setPrefix("/WEB-INF/templates/");
64-
templateResolver.setSuffix(".html");
65-
templateResolver.setTemplateMode("HTML5");
66-
return templateResolver;
67-
}
59+
@Bean
60+
@Description("Thymeleaf template resolver serving HTML 5")
61+
public ServletContextTemplateResolver templateResolver() {
62+
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
63+
templateResolver.setPrefix("/WEB-INF/templates/");
64+
templateResolver.setSuffix(".html");
65+
templateResolver.setTemplateMode("HTML5");
66+
return templateResolver;
67+
}
6868

69-
@Bean
70-
@Description("Thymeleaf template engine with Spring integration")
71-
public SpringTemplateEngine templateEngine() {
72-
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
73-
templateEngine.setTemplateResolver(templateResolver());
74-
final Set<IDialect> dialects = new HashSet<>();
75-
dialects.add(new CustomDialect());
76-
templateEngine.setAdditionalDialects(dialects);
77-
return templateEngine;
78-
}
69+
@Bean
70+
@Description("Thymeleaf template engine with Spring integration")
71+
public SpringTemplateEngine templateEngine() {
72+
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
73+
templateEngine.setTemplateResolver(templateResolver());
74+
final Set<IDialect> dialects = new HashSet<>();
75+
dialects.add(new CustomDialect());
76+
templateEngine.setAdditionalDialects(dialects);
77+
return templateEngine;
78+
}
7979

80-
@Bean
81-
@Description("Spring message resolver")
82-
public MessageSource messageSource() {
83-
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
84-
messageSource.setBasename("messages");
85-
return messageSource;
86-
}
80+
@Bean
81+
@Description("Spring message resolver")
82+
public MessageSource messageSource() {
83+
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
84+
messageSource.setBasename("messages");
85+
return messageSource;
86+
}
8787

88-
@Override
89-
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
90-
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
91-
}
88+
@Override
89+
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
90+
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
91+
}
9292

9393
}

‎spring-mvc-java/src/main/java/org/baeldung/spring/web/config/MainWebAppInitializer.java‎

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,37 @@
1414

1515
public class MainWebAppInitializer implements WebApplicationInitializer {
1616

17-
/**
18-
* Register and configure all Servlet container components necessary to power the web application.
19-
*/
20-
@Override
21-
public void onStartup(final ServletContext sc) throws ServletException {
22-
System.out.println("MainWebAppInitializer.onStartup()");
23-
24-
// Create the 'root' Spring application context
25-
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
26-
root.scan("org.baeldung.spring.web.config");
27-
// root.getEnvironment().setDefaultProfiles("embedded");
28-
29-
// Manages the lifecycle of the root application context
30-
sc.addListener(new ContextLoaderListener(root));
31-
32-
// Handles requests into the application
33-
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
34-
appServlet.setLoadOnStartup(1);
35-
final Set<String> mappingConflicts = appServlet.addMapping("/");
36-
if (!mappingConflicts.isEmpty()) {
37-
throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
38-
}
39-
}
17+
private static final String TMP_FOLDER = "C:/Users/ivan/Desktop/tmp";
18+
private static final int MAX_UPLOAD_SIZE = 5 * 1024 * 1024; // 5 MB
19+
20+
/**
21+
* Register and configure all Servlet container components necessary to power the web application.
22+
*/
23+
@Override
24+
public void onStartup(final ServletContext sc) throws ServletException {
25+
26+
// Create the 'root' Spring application context
27+
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
28+
root.scan("org.baeldung.spring.web.config");
29+
// root.getEnvironment().setDefaultProfiles("embedded");
30+
31+
// Manages the lifecycle of the root application context
32+
sc.addListener(new ContextLoaderListener(root));
33+
34+
// Handles requests into the application
35+
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
36+
appServlet.setLoadOnStartup(1);
37+
38+
// final MultipartConfigElement multipartConfigElement = new
39+
// MultipartConfigElement(TMP_FOLDER, MAX_UPLOAD_SIZE,
40+
// MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
41+
//
42+
// appServlet.setMultipartConfig(multipartConfigElement);
43+
44+
final Set<String> mappingConflicts = appServlet.addMapping("/");
45+
if (!mappingConflicts.isEmpty()) {
46+
throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
47+
}
48+
}
4049

4150
}

‎spring-mvc-java/src/main/java/org/baeldung/spring/web/config/WebConfig.java‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.context.annotation.ComponentScan;
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.core.io.ClassPathResource;
7+
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
78
import org.springframework.web.servlet.ViewResolver;
89
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
910
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
@@ -22,7 +23,19 @@ public WebConfig() {
2223
super();
2324
}
2425

25-
//
26+
// @Bean
27+
// public StandardServletMultipartResolver multipartResolver() {
28+
// return new StandardServletMultipartResolver();
29+
// }
30+
31+
@Bean(name = "multipartResolver")
32+
public CommonsMultipartResolver multipartResolver() {
33+
34+
final CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
35+
multipartResolver.setMaxUploadSize(100000);
36+
37+
return multipartResolver;
38+
}
2639

2740
@Override
2841
public void addViewControllers(final ViewControllerRegistry registry) {
@@ -56,4 +69,4 @@ public ViewResolver resourceBundleViewResolver() {
5669
return bean;
5770
}
5871

59-
}
72+
}

0 commit comments

Comments
 (0)