diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index bc81a89bec..f1c2b0b9f5 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -7,10 +7,10 @@ spring-mvc-java - parent-boot-1 + parent-boot-2 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-1 + ../parent-boot-2 @@ -49,33 +49,26 @@ com.fasterxml.jackson.core jackson-databind - ${jackson.version} javax.servlet javax.servlet-api - ${javax.servlet-api.version} - provided javax.servlet jstl - ${jstl.version} - runtime org.aspectj aspectjrt - ${aspectj.version} org.aspectj aspectjweaver - ${aspectj.version} @@ -87,7 +80,6 @@ net.sourceforge.htmlunit htmlunit - ${net.sourceforge.htmlunit} commons-logging @@ -111,7 +103,6 @@ com.jayway.jsonpath json-path - ${jsonpath.version} test @@ -128,11 +119,6 @@ - - javax.validation - validation-api - 1.1.0.Final - org.hibernate hibernate-validator @@ -170,13 +156,11 @@ maven-resources-plugin - ${maven-resources-plugin.version} org.apache.maven.plugins maven-war-plugin - ${maven-war-plugin.version} false @@ -266,18 +250,14 @@ - - 2.1.5.RELEASE - 2.9.4 + 3.0.9.RELEASE 5.2.5.Final 5.1.40 - 5.4.1.Final - 3.1.0 - 1.2 + 6.0.10.Final 19.0 diff --git a/spring-mvc-java/src/main/java/com/baeldung/app/Application.java b/spring-mvc-java/src/main/java/com/baeldung/app/Application.java index 301caffca9..68d078de78 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/app/Application.java +++ b/spring-mvc-java/src/main/java/com/baeldung/app/Application.java @@ -3,7 +3,7 @@ package com.baeldung.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; @EnableAutoConfiguration diff --git a/spring-mvc-java/src/main/java/com/baeldung/dialect/CustomDialect.java b/spring-mvc-java/src/main/java/com/baeldung/dialect/CustomDialect.java deleted file mode 100644 index 0c6a7c3ae0..0000000000 --- a/spring-mvc-java/src/main/java/com/baeldung/dialect/CustomDialect.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.dialect; - -import java.util.HashSet; -import java.util.Set; - -import com.baeldung.processor.NameProcessor; -import org.thymeleaf.dialect.AbstractDialect; -import org.thymeleaf.processor.IProcessor; - -public class CustomDialect extends AbstractDialect { - - @Override - public String getPrefix() { - return "custom"; - } - - @Override - public Set getProcessors() { - final Set processors = new HashSet(); - processors.add(new NameProcessor()); - return processors; - } - -} diff --git a/spring-mvc-java/src/main/java/com/baeldung/processor/NameProcessor.java b/spring-mvc-java/src/main/java/com/baeldung/processor/NameProcessor.java deleted file mode 100644 index 9a7857198c..0000000000 --- a/spring-mvc-java/src/main/java/com/baeldung/processor/NameProcessor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.processor; - -import org.thymeleaf.Arguments; -import org.thymeleaf.dom.Element; -import org.thymeleaf.processor.attr.AbstractTextChildModifierAttrProcessor; - -public class NameProcessor extends AbstractTextChildModifierAttrProcessor { - - public NameProcessor() { - super("name"); - } - - @Override - protected String getText(final Arguments arguements, final Element elements, final String attributeName) { - return "Hello, " + elements.getAttributeValue(attributeName) + "!"; - } - - @Override - public int getPrecedence() { - return 1000; - } - -} diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ClientWebConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ClientWebConfig.java index 1b30479685..de47f9f69e 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ClientWebConfig.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ClientWebConfig.java @@ -1,9 +1,7 @@ package com.baeldung.spring.web.config; -import java.util.HashSet; -import java.util.Set; - -import com.baeldung.dialect.CustomDialect; +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.Configuration; @@ -13,27 +11,28 @@ import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; -import org.thymeleaf.dialect.IDialect; import org.thymeleaf.spring4.SpringTemplateEngine; import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templateresolver.ServletContextTemplateResolver; @EnableWebMvc @Configuration -public class ClientWebConfig extends WebMvcConfigurerAdapter { +public class ClientWebConfig implements WebMvcConfigurer { public ClientWebConfig() { super(); } // API + + @Autowired + private ServletContext ctx; @Override public void addViewControllers(final ViewControllerRegistry registry) { - super.addViewControllers(registry); registry.addViewController("/sample.html"); } @@ -59,7 +58,7 @@ public class ClientWebConfig extends WebMvcConfigurerAdapter { @Bean @Description("Thymeleaf template resolver serving HTML 5") public ServletContextTemplateResolver templateResolver() { - final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); + final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx); templateResolver.setPrefix("/WEB-INF/templates/"); templateResolver.setSuffix(".html"); templateResolver.setTemplateMode("HTML5"); @@ -71,9 +70,6 @@ public class ClientWebConfig extends WebMvcConfigurerAdapter { public SpringTemplateEngine templateEngine() { final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.setTemplateResolver(templateResolver()); - final Set dialects = new HashSet<>(); - dialects.add(new CustomDialect()); - templateEngine.setAdditionalDialects(dialects); return templateEngine; } diff --git a/spring-mvc-java/src/test/java/com/baeldung/config/ControllerClassNameHandlerMappingConfig.java b/spring-mvc-java/src/test/java/com/baeldung/config/ControllerClassNameHandlerMappingConfig.java deleted file mode 100644 index 6e9318602f..0000000000 --- a/spring-mvc-java/src/test/java/com/baeldung/config/ControllerClassNameHandlerMappingConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.config; - -import com.baeldung.web.controller.handlermapping.WelcomeController; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.web.servlet.ViewResolver; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping; -import org.springframework.web.servlet.view.InternalResourceViewResolver; - -@Configuration -public class ControllerClassNameHandlerMappingConfig { - - @Bean - public ViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } - - @Bean - public ControllerClassNameHandlerMapping controllerClassNameHandlerMapping() { - ControllerClassNameHandlerMapping controllerClassNameHandlerMapping = new ControllerClassNameHandlerMapping(); - return controllerClassNameHandlerMapping; - } - - @Bean - public WelcomeController welcome() { - return new WelcomeController(); - } - - -} diff --git a/spring-mvc-java/src/test/java/com/baeldung/handlermappings/ControllerClassNameHandlerMappingIntegrationTest.java b/spring-mvc-java/src/test/java/com/baeldung/handlermappings/ControllerClassNameHandlerMappingIntegrationTest.java deleted file mode 100644 index b84998470d..0000000000 --- a/spring-mvc-java/src/test/java/com/baeldung/handlermappings/ControllerClassNameHandlerMappingIntegrationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.handlermappings; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import com.baeldung.config.ControllerClassNameHandlerMappingConfig; - -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextConfiguration(classes = ControllerClassNameHandlerMappingConfig.class) -public class ControllerClassNameHandlerMappingIntegrationTest { - - @Autowired - private WebApplicationContext webAppContext; - private MockMvc mockMvc; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build(); - } - - @Test - public void whenControllerClassNameMapping_thenMappedOK() throws Exception { - mockMvc.perform(get("/welcome")).andExpect(status().isOk()).andExpect(view().name("welcome")).andDo(print()); - } -} \ No newline at end of file diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java b/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java index 479b02e77f..e734676b98 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java +++ b/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java @@ -9,7 +9,6 @@ import org.junit.Test; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; -import com.gargoylesoftware.htmlunit.html.HtmlHeading1; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class HtmlUnitWebScrapingLiveTest { @@ -37,7 +36,7 @@ public class HtmlUnitWebScrapingLiveTest { final HtmlAnchor latestPostLink = (HtmlAnchor) page.getByXPath(xpath).get(0); final HtmlPage postPage = latestPostLink.click(); - final List h1 = (List) postPage.getByXPath("//h1"); + final List h1 = postPage.getByXPath("//h1"); Assert.assertTrue(h1.size() > 0); } diff --git a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java b/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java index 17a68d67a5..5b86b59095 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java +++ b/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java @@ -1,10 +1,14 @@ package com.baeldung.htmlunit; +import javax.servlet.ServletContext; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.thymeleaf.spring4.SpringTemplateEngine; import org.thymeleaf.spring4.view.ThymeleafViewResolver; @@ -13,8 +17,11 @@ import org.thymeleaf.templateresolver.ServletContextTemplateResolver; @Configuration @EnableWebMvc @ComponentScan(basePackages = { "com.baeldung.web.controller" }) -public class TestConfig extends WebMvcConfigurerAdapter { +public class TestConfig implements WebMvcConfigurer { + @Autowired + private ServletContext ctx; + @Bean public ViewResolver thymeleafViewResolver() { final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); @@ -25,7 +32,7 @@ public class TestConfig extends WebMvcConfigurerAdapter { @Bean public ServletContextTemplateResolver templateResolver() { - final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); + final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx); templateResolver.setPrefix("/WEB-INF/templates/"); templateResolver.setSuffix(".html"); templateResolver.setTemplateMode("HTML5");