Skip to content

Commit 49c8323

Browse files
authored
Merge pull request eugenp#4493 from eugenp/update-mvc-java
update to spring 5
2 parents 5344a0f + 9c1a666 commit 49c8323

9 files changed

Lines changed: 23 additions & 164 deletions

File tree

‎spring-mvc-java/pom.xml‎

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<name>spring-mvc-java</name>
88

99
<parent>
10-
<artifactId>parent-boot-1</artifactId>
10+
<artifactId>parent-boot-2</artifactId>
1111
<groupId>com.baeldung</groupId>
1212
<version>0.0.1-SNAPSHOT</version>
13-
<relativePath>../parent-boot-1</relativePath>
13+
<relativePath>../parent-boot-2</relativePath>
1414
</parent>
1515

1616
<dependencies>
@@ -49,33 +49,26 @@
4949
<dependency>
5050
<groupId>com.fasterxml.jackson.core</groupId>
5151
<artifactId>jackson-databind</artifactId>
52-
<version>${jackson.version}</version>
5352
</dependency>
5453

5554
<!-- web -->
5655
<dependency>
5756
<groupId>javax.servlet</groupId>
5857
<artifactId>javax.servlet-api</artifactId>
59-
<version>${javax.servlet-api.version}</version>
60-
<scope>provided</scope>
6158
</dependency>
6259
<dependency>
6360
<groupId>javax.servlet</groupId>
6461
<artifactId>jstl</artifactId>
65-
<version>${jstl.version}</version>
66-
<scope>runtime</scope>
6762
</dependency>
6863

6964
<!-- AOP -->
7065
<dependency>
7166
<groupId>org.aspectj</groupId>
7267
<artifactId>aspectjrt</artifactId>
73-
<version>${aspectj.version}</version>
7468
</dependency>
7569
<dependency>
7670
<groupId>org.aspectj</groupId>
7771
<artifactId>aspectjweaver</artifactId>
78-
<version>${aspectj.version}</version>
7972
</dependency>
8073

8174
<!-- common -->
@@ -87,7 +80,6 @@
8780
<dependency>
8881
<groupId>net.sourceforge.htmlunit</groupId>
8982
<artifactId>htmlunit</artifactId>
90-
<version>${net.sourceforge.htmlunit}</version>
9183
<exclusions>
9284
<exclusion>
9385
<artifactId>commons-logging</artifactId>
@@ -111,7 +103,6 @@
111103
<dependency>
112104
<groupId>com.jayway.jsonpath</groupId>
113105
<artifactId>json-path</artifactId>
114-
<version>${jsonpath.version}</version>
115106
<scope>test</scope>
116107
</dependency>
117108
<dependency>
@@ -128,11 +119,6 @@
128119
</dependency>
129120

130121
<!-- Validation -->
131-
<dependency>
132-
<groupId>javax.validation</groupId>
133-
<artifactId>validation-api</artifactId>
134-
<version>1.1.0.Final</version>
135-
</dependency>
136122
<dependency>
137123
<groupId>org.hibernate</groupId>
138124
<artifactId>hibernate-validator</artifactId>
@@ -170,13 +156,11 @@
170156

171157
<plugin>
172158
<artifactId>maven-resources-plugin</artifactId>
173-
<version>${maven-resources-plugin.version}</version>
174159
</plugin>
175160

176161
<plugin>
177162
<groupId>org.apache.maven.plugins</groupId>
178163
<artifactId>maven-war-plugin</artifactId>
179-
<version>${maven-war-plugin.version}</version>
180164
<configuration>
181165
<failOnMissingWebXml>false</failOnMissingWebXml>
182166
</configuration>
@@ -266,18 +250,14 @@
266250
</profiles>
267251

268252
<properties>
269-
<!-- Spring -->
270-
<thymeleaf.version>2.1.5.RELEASE</thymeleaf.version>
271-
<jackson.version>2.9.4</jackson.version>
253+
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
272254

273255
<!-- persistence -->
274256
<hibernate.version>5.2.5.Final</hibernate.version>
275257
<mysql-connector-java.version>5.1.40</mysql-connector-java.version>
276258

277259
<!-- various -->
278-
<hibernate-validator.version>5.4.1.Final</hibernate-validator.version>
279-
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
280-
<jstl.version>1.2</jstl.version>
260+
<hibernate-validator.version>6.0.10.Final</hibernate-validator.version>
281261

282262
<!-- util -->
283263
<guava.version>19.0</guava.version>

‎spring-mvc-java/src/main/java/com/baeldung/app/Application.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
6-
import org.springframework.boot.web.support.SpringBootServletInitializer;
6+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
77
import org.springframework.context.annotation.ComponentScan;
88

99
@EnableAutoConfiguration

‎spring-mvc-java/src/main/java/com/baeldung/dialect/CustomDialect.java‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎spring-mvc-java/src/main/java/com/baeldung/processor/NameProcessor.java‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.baeldung.spring.web.config;
22

3-
import java.util.HashSet;
4-
import java.util.Set;
5-
6-
import com.baeldung.dialect.CustomDialect;
3+
import javax.servlet.ServletContext;
4+
import org.springframework.beans.factory.annotation.Autowired;
75
import org.springframework.context.MessageSource;
86
import org.springframework.context.annotation.Bean;
97
import org.springframework.context.annotation.Configuration;
@@ -13,27 +11,28 @@
1311
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
1412
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
1513
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
16-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
14+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
1715
import org.springframework.web.servlet.view.InternalResourceViewResolver;
1816
import org.springframework.web.servlet.view.JstlView;
19-
import org.thymeleaf.dialect.IDialect;
2017
import org.thymeleaf.spring4.SpringTemplateEngine;
2118
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
2219
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
2320

2421
@EnableWebMvc
2522
@Configuration
26-
public class ClientWebConfig extends WebMvcConfigurerAdapter {
23+
public class ClientWebConfig implements WebMvcConfigurer {
2724

2825
public ClientWebConfig() {
2926
super();
3027
}
3128

3229
// API
30+
31+
@Autowired
32+
private ServletContext ctx;
3333

3434
@Override
3535
public void addViewControllers(final ViewControllerRegistry registry) {
36-
super.addViewControllers(registry);
3736

3837
registry.addViewController("/sample.html");
3938
}
@@ -59,7 +58,7 @@ public ViewResolver viewResolver() {
5958
@Bean
6059
@Description("Thymeleaf template resolver serving HTML 5")
6160
public ServletContextTemplateResolver templateResolver() {
62-
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
61+
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx);
6362
templateResolver.setPrefix("/WEB-INF/templates/");
6463
templateResolver.setSuffix(".html");
6564
templateResolver.setTemplateMode("HTML5");
@@ -71,9 +70,6 @@ public ServletContextTemplateResolver templateResolver() {
7170
public SpringTemplateEngine templateEngine() {
7271
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
7372
templateEngine.setTemplateResolver(templateResolver());
74-
final Set<IDialect> dialects = new HashSet<>();
75-
dialects.add(new CustomDialect());
76-
templateEngine.setAdditionalDialects(dialects);
7773
return templateEngine;
7874
}
7975

‎spring-mvc-java/src/test/java/com/baeldung/config/ControllerClassNameHandlerMappingConfig.java‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎spring-mvc-java/src/test/java/com/baeldung/handlermappings/ControllerClassNameHandlerMappingIntegrationTest.java‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import com.gargoylesoftware.htmlunit.WebClient;
1111
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
12-
import com.gargoylesoftware.htmlunit.html.HtmlHeading1;
1312
import com.gargoylesoftware.htmlunit.html.HtmlPage;
1413

1514
public class HtmlUnitWebScrapingLiveTest {
@@ -37,7 +36,7 @@ public void givenBaeldungArchive_whenRetrievingArticle_thenHasH1() throws Except
3736
final HtmlAnchor latestPostLink = (HtmlAnchor) page.getByXPath(xpath).get(0);
3837
final HtmlPage postPage = latestPostLink.click();
3938

40-
final List<HtmlHeading1> h1 = (List<HtmlHeading1>) postPage.getByXPath("//h1");
39+
final List<Object> h1 = postPage.getByXPath("//h1");
4140

4241
Assert.assertTrue(h1.size() > 0);
4342
}

‎spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.baeldung.htmlunit;
22

3+
import javax.servlet.ServletContext;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
36
import org.springframework.context.annotation.Bean;
47
import org.springframework.context.annotation.ComponentScan;
58
import org.springframework.context.annotation.Configuration;
69
import org.springframework.web.servlet.ViewResolver;
710
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
11+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
812
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
913
import org.thymeleaf.spring4.SpringTemplateEngine;
1014
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
@@ -13,8 +17,11 @@
1317
@Configuration
1418
@EnableWebMvc
1519
@ComponentScan(basePackages = { "com.baeldung.web.controller" })
16-
public class TestConfig extends WebMvcConfigurerAdapter {
20+
public class TestConfig implements WebMvcConfigurer {
1721

22+
@Autowired
23+
private ServletContext ctx;
24+
1825
@Bean
1926
public ViewResolver thymeleafViewResolver() {
2027
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
@@ -25,7 +32,7 @@ public ViewResolver thymeleafViewResolver() {
2532

2633
@Bean
2734
public ServletContextTemplateResolver templateResolver() {
28-
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
35+
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx);
2936
templateResolver.setPrefix("/WEB-INF/templates/");
3037
templateResolver.setSuffix(".html");
3138
templateResolver.setTemplateMode("HTML5");

0 commit comments

Comments
 (0)