JAVA-29172 :- Upgrade spring-mvc-basics to Spring Boot 3 (#15555)
This commit is contained in:
parent
c41bd80850
commit
290d4d266a
@ -10,9 +10,9 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>parent-boot-3</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-3</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@ -20,11 +20,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>${commons-fileupload.version}</version>
|
||||
</dependency>
|
||||
<!-- to enable JSP -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
@ -33,6 +28,12 @@
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>${jstl-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>${jaxb-runtime.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -40,10 +41,12 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>${jaxb-runtime.version}</version>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>${rest-assured-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -61,7 +64,9 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<jaxb-runtime.version>2.3.5</jaxb-runtime.version>
|
||||
<jaxb-runtime.version>4.0.1</jaxb-runtime.version>
|
||||
<rest-assured-version>5.4.0</rest-assured-version>
|
||||
<jstl-version>1.2</jstl-version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -1,9 +1,9 @@
|
||||
package com.baeldung.config;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRegistration;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRegistration;
|
||||
import org.springframework.web.WebApplicationInitializer;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.baeldung.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class Employee {
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.baeldung.spring.web.config;
|
||||
|
||||
import jakarta.servlet.MultipartConfigElement;
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.ui.context.support.ResourceBundleThemeSource;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
import org.springframework.web.servlet.View;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
||||
@ -19,8 +21,6 @@ import org.springframework.web.servlet.view.BeanNameViewResolver;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.servlet.view.JstlView;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//@EnableWebMvc
|
||||
//@ComponentScan(basePackages = { "com.baeldung.web.controller" })
|
||||
@Configuration
|
||||
@ -32,12 +32,12 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.setViewName("index");
|
||||
}
|
||||
|
||||
/** Multipart file uploading configuratioin */
|
||||
@Bean
|
||||
public CommonsMultipartResolver multipartResolver() throws IOException {
|
||||
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
|
||||
resolver.setMaxUploadSize(10000000);
|
||||
return resolver;
|
||||
public MultipartConfigElement multipartConfigElement() {
|
||||
MultipartConfigFactory factory = new MultipartConfigFactory();
|
||||
factory.setMaxFileSize(DataSize.ofBytes(10000000L));
|
||||
factory.setMaxRequestSize(DataSize.ofBytes(10000000L));
|
||||
return factory.createMultipartConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -8,7 +9,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
@ -16,32 +16,32 @@ public class RequestMappingShortcutsController {
|
||||
|
||||
@GetMapping("/get")
|
||||
public @ResponseBody ResponseEntity<String> get() {
|
||||
return new ResponseEntity<String>("GET Response", HttpStatus.OK);
|
||||
return new ResponseEntity<>("GET Response", HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public @ResponseBody ResponseEntity<String> getById(@PathVariable String id) {
|
||||
return new ResponseEntity<String>("GET Response : " + id, HttpStatus.OK);
|
||||
return new ResponseEntity<>("GET Response : " + id, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/post")
|
||||
public @ResponseBody ResponseEntity<String> post() {
|
||||
return new ResponseEntity<String>("POST Response", HttpStatus.OK);
|
||||
return new ResponseEntity<>("POST Response", HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PutMapping("/put")
|
||||
public @ResponseBody ResponseEntity<String> put() {
|
||||
return new ResponseEntity<String>("PUT Response", HttpStatus.OK);
|
||||
return new ResponseEntity<>("PUT Response", HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
public @ResponseBody ResponseEntity<String> delete() {
|
||||
return new ResponseEntity<String>("DELETE Response", HttpStatus.OK);
|
||||
return new ResponseEntity<>("DELETE Response", HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping("/patch")
|
||||
public @ResponseBody ResponseEntity<String> patch() {
|
||||
return new ResponseEntity<String>("PATCH Response", HttpStatus.OK);
|
||||
return new ResponseEntity<>("PATCH Response", HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.baeldung.web.controller.handlermapping;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.AbstractController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class BeanNameHandlerMappingController extends AbstractController {
|
||||
@Override
|
||||
|
@ -1,11 +1,10 @@
|
||||
package com.baeldung.web.controller.handlermapping;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.AbstractController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class SimpleUrlMappingController extends AbstractController {
|
||||
@Override
|
||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.baeldung.web.controller.handlermapping;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.AbstractController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Controller
|
||||
public class WelcomeController extends AbstractController {
|
||||
|
||||
|
@ -5,7 +5,6 @@ import java.util.Map;
|
||||
|
||||
import com.baeldung.web.controller.handlermapping.SimpleUrlMappingController;
|
||||
import com.baeldung.web.controller.handlermapping.BeanNameHandlerMappingController;
|
||||
import com.baeldung.web.controller.handlermapping.WelcomeController;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
|
||||
|
@ -30,7 +30,7 @@ public class BeanNameMappingConfigIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
MockitoAnnotations.openMocks(this);
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class HandlerMappingDefaultConfigIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
MockitoAnnotations.openMocks(this);
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build();
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class HandlerMappingPriorityConfigIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
MockitoAnnotations.openMocks(this);
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build();
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class SimpleUrlMappingConfigIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
MockitoAnnotations.openMocks(this);
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user