Merge modules (#1983)
This commit is contained in:
parent
494a9c1af1
commit
8fcb5494a3
1
pom.xml
1
pom.xml
|
@ -166,7 +166,6 @@
|
||||||
<module>spring-mvc-java</module>
|
<module>spring-mvc-java</module>
|
||||||
<module>spring-mvc-tiles</module>
|
<module>spring-mvc-tiles</module>
|
||||||
<module>spring-mvc-velocity</module>
|
<module>spring-mvc-velocity</module>
|
||||||
<module>spring-mvc-web-vs-initializer</module>
|
|
||||||
<module>spring-mvc-webflow</module>
|
<module>spring-mvc-webflow</module>
|
||||||
<module>spring-mvc-xml</module>
|
<module>spring-mvc-xml</module>
|
||||||
<module>spring-mvc-simple</module>
|
<module>spring-mvc-simple</module>
|
||||||
|
|
|
@ -22,3 +22,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
- [Guide to Spring Handler Mappings](http://www.baeldung.com/spring-handler-mappings)
|
- [Guide to Spring Handler Mappings](http://www.baeldung.com/spring-handler-mappings)
|
||||||
- [Uploading and Displaying Excel Files with Spring MVC](http://www.baeldung.com/spring-mvc-excel-files)
|
- [Uploading and Displaying Excel Files with Spring MVC](http://www.baeldung.com/spring-mvc-excel-files)
|
||||||
- [Spring MVC Custom Validation](http://www.baeldung.com/spring-mvc-custom-validator)
|
- [Spring MVC Custom Validation](http://www.baeldung.com/spring-mvc-custom-validator)
|
||||||
|
- [web.xml vs Initializer with Spring](http://www.baeldung.com/spring-xml-vs-java-config)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.config;
|
package com.baeldung.config;
|
||||||
|
|
||||||
import org.springframework.web.WebApplicationInitializer;
|
import org.springframework.web.WebApplicationInitializer;
|
||||||
import org.springframework.web.context.ContextLoaderListener;
|
import org.springframework.web.context.ContextLoaderListener;
|
|
@ -1,13 +0,0 @@
|
||||||
*.class
|
|
||||||
|
|
||||||
#folders#
|
|
||||||
/target
|
|
||||||
/neoDb*
|
|
||||||
/data
|
|
||||||
/src/main/webapp/WEB-INF/classes
|
|
||||||
*/META-INF/*
|
|
||||||
|
|
||||||
# Packaged files #
|
|
||||||
*.jar
|
|
||||||
*.war
|
|
||||||
*.ear
|
|
|
@ -1,2 +0,0 @@
|
||||||
### Relevant Articles:
|
|
||||||
- [web.xml vs Initializer with Spring](http://www.baeldung.com/spring-xml-vs-java-config)
|
|
|
@ -1,193 +0,0 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>spring-mvc-web-vs-initializer</artifactId>
|
|
||||||
<version>0.1-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<name>spring-mvc-web-vs-initializer</name>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<artifactId>parent-boot-4</artifactId>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<relativePath>../parent-boot-4</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Spring -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-web</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-webmvc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-context</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- web -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>jstl</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- util -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
<version>${guava.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- test scoped -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.assertj</groupId>
|
|
||||||
<artifactId>assertj-core</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.easymock</groupId>
|
|
||||||
<artifactId>easymock</artifactId>
|
|
||||||
<version>${easymock.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-framework-bom</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-core</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<finalName>spring-mvc-web-vs-initializer</finalName>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>integration</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>integration-test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>test</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/*LiveTest.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
<includes>
|
|
||||||
<include>**/*IntegrationTest.java</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<systemPropertyVariables>
|
|
||||||
<test.mime>json</test.mime>
|
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<!-- Spring -->
|
|
||||||
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
|
||||||
<guava.version>19.0</guava.version>
|
|
||||||
<easymock.version>3.4</easymock.version>
|
|
||||||
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,25 +0,0 @@
|
||||||
package org.baeldung.config;
|
|
||||||
|
|
||||||
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.WebMvcConfigurerAdapter;
|
|
||||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableWebMvc
|
|
||||||
@ComponentScan(basePackages = "org.baeldung.controller.java")
|
|
||||||
public class MvcConfig extends WebMvcConfigurerAdapter {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ViewResolver viewResolver() {
|
|
||||||
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
|
|
||||||
viewResolver.setPrefix("/WEB-INF/view/");
|
|
||||||
viewResolver.setSuffix(".jsp");
|
|
||||||
|
|
||||||
return viewResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package org.baeldung.controller.java;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class JavaController {
|
|
||||||
|
|
||||||
@RequestMapping(value = "/endpoint")
|
|
||||||
public ModelAndView handleRequestFromJavaConfiguredServlet() {
|
|
||||||
ModelAndView mv = new ModelAndView();
|
|
||||||
mv.setViewName("from-java");
|
|
||||||
|
|
||||||
return mv;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package org.baeldung.controller.xml;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class XmlController {
|
|
||||||
|
|
||||||
@RequestMapping(value = "/endpoint")
|
|
||||||
public ModelAndView handleRequestFromXmlConfiguredServlet() {
|
|
||||||
ModelAndView mv = new ModelAndView();
|
|
||||||
mv.setViewName("from-xml");
|
|
||||||
|
|
||||||
return mv;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
<html>
|
|
||||||
<head></head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>Java</h1>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,7 +0,0 @@
|
||||||
<html>
|
|
||||||
<head></head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>XML</h1>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,24 +0,0 @@
|
||||||
<web-app
|
|
||||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
|
||||||
version="3.0">
|
|
||||||
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>xml-servlet</servlet-name>
|
|
||||||
<servlet-class>
|
|
||||||
org.springframework.web.servlet.DispatcherServlet
|
|
||||||
</servlet-class>
|
|
||||||
<init-param>
|
|
||||||
<param-name>contextConfigLocation</param-name>
|
|
||||||
<param-value>classpath*:mvc-configuration.xml</param-value>
|
|
||||||
</init-param>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>xml-servlet</servlet-name>
|
|
||||||
<url-pattern>/xml-servlet/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
</web-app>
|
|
|
@ -1,45 +0,0 @@
|
||||||
package org.baeldung.controller;
|
|
||||||
|
|
||||||
import org.baeldung.config.MvcConfig;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
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.AnnotationConfigWebContextLoader;
|
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@WebAppConfiguration
|
|
||||||
@ContextConfiguration(loader=AnnotationConfigWebContextLoader.class, classes = MvcConfig.class)
|
|
||||||
public class JavaServletIntegrationTest {
|
|
||||||
|
|
||||||
private MockMvc mockMvc;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WebApplicationContext wac;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testJavaEndpoint() throws Exception {
|
|
||||||
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/endpoint"))
|
|
||||||
.andReturn()
|
|
||||||
.getModelAndView();
|
|
||||||
|
|
||||||
// validate view name
|
|
||||||
Assert.assertSame(mv.getViewName(), "from-java");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
package org.baeldung.controller;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
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.GenericXmlWebContextLoader;
|
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@WebAppConfiguration
|
|
||||||
@ContextConfiguration(loader=GenericXmlWebContextLoader.class, locations = "classpath*:mvc-configuration.xml")
|
|
||||||
public class XmlServletIntegrationTest {
|
|
||||||
|
|
||||||
private MockMvc mockMvc;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WebApplicationContext wac;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testXmlEndpoint() throws Exception {
|
|
||||||
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/endpoint"))
|
|
||||||
.andReturn()
|
|
||||||
.getModelAndView();
|
|
||||||
|
|
||||||
// validate view name
|
|
||||||
Assert.assertSame(mv.getViewName(), "from-xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue