Migrated spring-mvc-basics to a Spring Boot project
This commit is contained in:
parent
ed7630c2d0
commit
802000d545
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
|
@ -6,87 +7,49 @@
|
|||
<artifactId>spring-mvc-basics</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>spring-mvc-basics</name>
|
||||
<packaging>war</packaging>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-spring-5</artifactId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-spring-5</relativePath>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- to enable JSP -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${javax.servlet-api.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||
<version>${javax.jsp-api.version}</version>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>${jstl.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>${jayway.json-path.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>${rest-assured.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>${hamcrest.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>spring-mvc-basics</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>
|
||||
<mainClass>com.baeldung.Application</mainClass>
|
||||
<layout>JAR</layout>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
|
||||
<javax.jsp-api.version>2.3.3</javax.jsp-api.version>
|
||||
<jayway.json-path.version>2.4.0</jayway.json-path.version>
|
||||
<rest-assured.version>4.0.0</rest-assured.version>
|
||||
<hamcrest.version>1.3</hamcrest.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
package com.baeldung.spring.web.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
|
@ -13,9 +11,9 @@ import org.springframework.web.servlet.view.JstlView;
|
|||
import org.springframework.web.servlet.view.ResourceBundleViewResolver;
|
||||
import org.springframework.web.servlet.view.XmlViewResolver;
|
||||
|
||||
@EnableWebMvc
|
||||
//@EnableWebMvc
|
||||
//@ComponentScan(basePackages = { "com.baeldung.web.controller" })
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = { "com.baeldung.web.controller" })
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +31,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
bean.setOrder(2);
|
||||
return bean;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ViewResolver resourceBundleViewResolver() {
|
||||
final ResourceBundleViewResolver bean = new ResourceBundleViewResolver();
|
||||
|
@ -41,7 +39,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
bean.setOrder(0);
|
||||
return bean;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ViewResolver xmlViewResolver() {
|
||||
final XmlViewResolver bean = new XmlViewResolver();
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
server.servlet.context-path=/spring-mvc-basics
|
|
@ -1,17 +1,9 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import com.baeldung.config.AppInitializer;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { AppInitializer.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@WebAppConfiguration
|
||||
@SpringBootTest
|
||||
public class SpringContextIntegrationTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.http.HttpStatus;
|
|||
import io.restassured.RestAssured;
|
||||
|
||||
public class SampleControllerLiveTest {
|
||||
|
||||
|
||||
private static final String SERVICE_BASE_URL = "/spring-mvc-basics";
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue