diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..a3339d120
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2015-Present Pivotal Software Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/README.md b/README.md
index d0f5de48f..1b9da2dbb 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+# spring-mvc-showcase is no longer actively maintained by VMware, Inc.
+
Spring MVC Showcase
-------------------
Demonstrates the capabilities of the Spring MVC web framework through small, simple examples.
@@ -24,27 +26,20 @@ Clone the repository:
$ git clone git://github.com/SpringSource/spring-mvc-showcase.git
-If this is your first time using Github, review http://help.github.com to learn the basics.
+If this is your first time using Github, review https://help.github.com to learn the basics.
To run the application:
-------------------
From the command line with Maven:
$ cd spring-mvc-showcase
- $ mvn tomcat7:run [-Dmaven.tomcat.port=] (In case 8080 is busy]
-
-or
-
-In your preferred IDE such as SpringSource Tool Suite (STS) or IDEA:
-
-* Import spring-mvc-showcase as a Maven Project
-* Drag-n-drop the project onto the "SpringSource tc Server Developer Edition" or another Servlet 2.5 or > Server to run, such as Tomcat.
+ $ mvn jetty:run
Access the deployed web application at: http://localhost:8080/spring-mvc-showcase/
Note:
-------------------
-This showcase originated from a [blog post](http://blog.springsource.com/2010/07/22/spring-mvc-3-showcase/) and was adapted into a SpringOne presentation called [Mastering MVC 3](http://www.infoq.com/presentations/Mastering-Spring-MVC-3).
+This showcase originated from a [blog post](https://spring.io/blog/2010/07/22/spring-mvc-3-showcase/) and was adapted into a SpringOne presentation called [Mastering MVC 3](https://www.infoq.com/presentations/Mastering-Spring-MVC-3).
A screen cast showing the showcase in action is [available in QuickTime format](http://s3.springsource.org/MVC/mvc-showcase-screencast.mov).
diff --git a/pom.xml b/pom.xml
index 7268aff9a..900d42021 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,38 +1,39 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
4.0.0org.springframework.samplesspring-mvc-showcasespring-mvc-showcasewar1.0.0-BUILD-SNAPSHOT
+
- 1.7
- 4.1.0.RELEASE
- 3.2.0.RELEASE
+ 1.8
+ 5.0.4.RELEASE1.8.1
- 1.6.1
+
org.springframeworkspring-context${org.springframework-version}
-
-
-
- commons-logging
- commons-logging
-
- org.springframeworkspring-webmvc${org.springframework-version}
+
+
+
+ org.springframework.security
+ spring-security-web
+ 5.0.0.RELEASE
+
+
org.aspectj
@@ -42,27 +43,14 @@
- org.slf4j
- slf4j-api
- ${org.slf4j-version}
+ org.apache.logging.log4j
+ log4j-core
+ LATEST
- org.slf4j
- jcl-over-slf4j
- ${org.slf4j-version}
- runtime
-
-
- org.slf4j
- slf4j-log4j12
- ${org.slf4j-version}
- runtime
-
-
- log4j
- log4j
- 1.2.16
- runtime
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ LATEST
@@ -72,93 +60,80 @@
1
-
+
- org.apache.tomcat
- tomcat-servlet-api
- 7.0.30
+ javax.servlet
+ javax.servlet-api
+ 3.1.0providedjavax.servlet.jsp
- jsp-api
- 2.1
+ javax.servlet.jsp-api
+ 2.3.2-b02provided
- javax.servlet.jsp.jstl
- jstl-api
- 1.2
-
-
- javax.servlet
- servlet-api
-
-
-
-
- org.glassfish.web
- jstl-impl
+ javax.servlet
+ jstl1.2
-
-
- javax.servlet
- servlet-api
-
- com.fasterxml.jackson.corejackson-databind
- 2.4.1
+ 2.9.3com.rometoolsrome
- 1.5.0
+ 1.9.0javax.validationvalidation-api
- 1.0.0.GA
+ 2.0.1.Final
- org.hibernate
+ org.hibernate.validatorhibernate-validator
- 4.1.0.Final
+ 6.0.7.Final
-
+
+ javax.el
+ javax.el-api
+ 3.0.1-b04
+
+
+ org.glassfish
+ javax.el
+ 3.0.1-b08
+
+
joda-timejoda-time
- 2.3
+ 2.9.9commons-fileuploadcommons-fileupload
- 1.2.2
+ 1.3.3commons-iocommons-io
- 2.0.1
+ 2.5
-
-
- org.springframework.security
- spring-security-web
- ${org.springframework.security-version}
-
@@ -170,19 +145,19 @@
junitjunit
- 4.11
+ 4.12test
- xmlunit
- xmlunit
- 1.2
+ org.xmlunit
+ xmlunit-matchers
+ 2.5.1testcom.jayway.jsonpathjson-path
- 0.8.1
+ 2.4.0test
@@ -192,39 +167,30 @@
test
-
-
-
- org.springframework.maven.snapshot
- Spring Maven Snapshot Repository
- http://repo.spring.io/snapshot
- false
- true
-
-
-
- org.springframework.maven.milestone
- Spring Maven Milestone Repository
- http://repo.spring.io/milestone
- false
-
-
+
${project.artifactId}org.apache.maven.pluginsmaven-compiler-plugin
- 2.3.2
+ 3.7.0${java-version}${java-version}
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+ false
+
+ org.apache.maven.pluginsmaven-surefire-plugin
- 2.12
+ 2.20.1**/*Tests.java
@@ -252,10 +218,8 @@
org.codehaus.mojoaspectj-maven-plugin
-
- 1.2
+ 1.11
-
org.aspectjaspectjrt
@@ -270,26 +234,22 @@
- compile
- test-compile
+ compile
+ test-compiletrue
+ ${java-version}${java-version}${java-version}
-
- org.apache.tomcat.maven
- tomcat7-maven-plugin
- 2.2
- org.eclipse.jettyjetty-maven-plugin
- 9.0.6.v20130930
+ 9.4.8.v20171121/${project.artifactId}
diff --git a/src/main/java/org/springframework/samples/mvc/async/CallableController.java b/src/main/java/org/springframework/samples/mvc/async/CallableController.java
index 4ea6ec86a..0fa649434 100644
--- a/src/main/java/org/springframework/samples/mvc/async/CallableController.java
+++ b/src/main/java/org/springframework/samples/mvc/async/CallableController.java
@@ -5,6 +5,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -15,7 +16,7 @@
public class CallableController {
- @RequestMapping("/response-body")
+ @GetMapping("/response-body")
public @ResponseBody Callable callable() {
return new Callable() {
@@ -27,50 +28,38 @@ public String call() throws Exception {
};
}
- @RequestMapping("/view")
+ @GetMapping("/view")
public Callable callableWithView(final Model model) {
-
- return new Callable() {
- @Override
- public String call() throws Exception {
- Thread.sleep(2000);
- model.addAttribute("foo", "bar");
- model.addAttribute("fruit", "apple");
- return "views/html";
- }
+ return () -> {
+ Thread.sleep(2000);
+ model.addAttribute("foo", "bar");
+ model.addAttribute("fruit", "apple");
+ return "views/html";
};
}
- @RequestMapping("/exception")
+ @GetMapping("/exception")
public @ResponseBody Callable callableWithException(
final @RequestParam(required=false, defaultValue="true") boolean handled) {
- return new Callable() {
- @Override
- public String call() throws Exception {
- Thread.sleep(2000);
- if (handled) {
- // see handleException method further below
- throw new IllegalStateException("Callable error");
- }
- else {
- throw new IllegalArgumentException("Callable error");
- }
+ return () -> {
+ Thread.sleep(2000);
+ if (handled) {
+ // see handleException method further below
+ throw new IllegalStateException("Callable error");
+ }
+ else {
+ throw new IllegalArgumentException("Callable error");
}
};
}
- @RequestMapping("/custom-timeout-handling")
+ @GetMapping("/custom-timeout-handling")
public @ResponseBody WebAsyncTask callableWithCustomTimeoutHandling() {
-
- Callable callable = new Callable() {
- @Override
- public String call() throws Exception {
- Thread.sleep(2000);
- return "Callable result";
- }
+ Callable callable = () -> {
+ Thread.sleep(2000);
+ return "Callable result";
};
-
return new WebAsyncTask(1000, callable);
}
diff --git a/src/main/java/org/springframework/samples/mvc/async/DeferredResultController.java b/src/main/java/org/springframework/samples/mvc/async/DeferredResultController.java
index 51b8e6d6a..41edfe72b 100644
--- a/src/main/java/org/springframework/samples/mvc/async/DeferredResultController.java
+++ b/src/main/java/org/springframework/samples/mvc/async/DeferredResultController.java
@@ -6,6 +6,7 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;
@@ -15,41 +16,41 @@
@RequestMapping("/async")
public class DeferredResultController {
- private final Queue> responseBodyQueue = new ConcurrentLinkedQueue>();
+ private final Queue> responseBodyQueue = new ConcurrentLinkedQueue<>();
- private final Queue> mavQueue = new ConcurrentLinkedQueue>();
+ private final Queue> mavQueue = new ConcurrentLinkedQueue<>();
- private final Queue> exceptionQueue = new ConcurrentLinkedQueue>();
+ private final Queue> exceptionQueue = new ConcurrentLinkedQueue<>();
- @RequestMapping("/deferred-result/response-body")
+ @GetMapping("/deferred-result/response-body")
public @ResponseBody DeferredResult deferredResult() {
- DeferredResult result = new DeferredResult();
+ DeferredResult result = new DeferredResult<>();
this.responseBodyQueue.add(result);
return result;
}
- @RequestMapping("/deferred-result/model-and-view")
+ @GetMapping("/deferred-result/model-and-view")
public DeferredResult deferredResultWithView() {
- DeferredResult result = new DeferredResult();
+ DeferredResult result = new DeferredResult<>();
this.mavQueue.add(result);
return result;
}
- @RequestMapping("/deferred-result/exception")
+ @GetMapping("/deferred-result/exception")
public @ResponseBody DeferredResult deferredResultWithException() {
- DeferredResult result = new DeferredResult();
+ DeferredResult result = new DeferredResult<>();
this.exceptionQueue.add(result);
return result;
}
- @RequestMapping("/deferred-result/timeout-value")
+ @GetMapping("/deferred-result/timeout-value")
public @ResponseBody DeferredResult deferredResultWithTimeoutValue() {
// Provide a default result in case of timeout and override the timeout value
// set in src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
- return new DeferredResult(1000L, "Deferred result after timeout");
+ return new DeferredResult<>(1000L, "Deferred result after timeout");
}
@Scheduled(fixedRate=2000)
diff --git a/src/main/java/org/springframework/samples/mvc/async/TimeoutCallableProcessingInterceptor.java b/src/main/java/org/springframework/samples/mvc/async/TimeoutCallableProcessingInterceptor.java
index 5eee8c583..c5440d63c 100644
--- a/src/main/java/org/springframework/samples/mvc/async/TimeoutCallableProcessingInterceptor.java
+++ b/src/main/java/org/springframework/samples/mvc/async/TimeoutCallableProcessingInterceptor.java
@@ -8,7 +8,7 @@
public class TimeoutCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter {
@Override
- public Object handleTimeout(NativeWebRequest request, Callable task) throws Exception {
+ public Object handleTimeout(NativeWebRequest request, Callable task) {
throw new IllegalStateException("[" + task.getClass().getName() + "] timed out");
}
diff --git a/src/main/java/org/springframework/samples/mvc/config/MvcShowcaseAppInitializer.java b/src/main/java/org/springframework/samples/mvc/config/MvcShowcaseAppInitializer.java
new file mode 100644
index 000000000..f0c83853b
--- /dev/null
+++ b/src/main/java/org/springframework/samples/mvc/config/MvcShowcaseAppInitializer.java
@@ -0,0 +1,34 @@
+package org.springframework.samples.mvc.config;
+
+import javax.servlet.Filter;
+
+import org.springframework.web.filter.DelegatingFilterProxy;
+import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
+
+/**
+ * Initialize the Servlet container. This class is detected by the Servlet
+ * container on startup.
+ */
+public class MvcShowcaseAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
+
+ @Override
+ protected Class>[] getRootConfigClasses() {
+ return new Class[] { RootConfig.class };
+ }
+
+ @Override
+ protected Class>[] getServletConfigClasses() {
+ return new Class[] { WebMvcConfig.class };
+ }
+
+ @Override
+ protected String[] getServletMappings() {
+ return new String[] { "/" };
+ }
+
+ @Override
+ protected Filter[] getServletFilters() {
+ return new Filter[] { new DelegatingFilterProxy("csrfFilter") };
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/mvc/config/RootConfig.java b/src/main/java/org/springframework/samples/mvc/config/RootConfig.java
new file mode 100644
index 000000000..449d95e7f
--- /dev/null
+++ b/src/main/java/org/springframework/samples/mvc/config/RootConfig.java
@@ -0,0 +1,31 @@
+package org.springframework.samples.mvc.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.web.csrf.CsrfFilter;
+import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
+import org.springframework.security.web.servlet.support.csrf.CsrfRequestDataValueProcessor;
+import org.springframework.web.servlet.support.RequestDataValueProcessor;
+
+// Root Context: defines shared resources visible to all other web components
+
+@Configuration
+public class RootConfig {
+
+ // CSRF protection. Here we only include the CsrfFilter instead of all of Spring Security.
+ // See https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#csrf
+ // for more information on Spring Security's CSRF protection
+
+ @Bean
+ public CsrfFilter csrfFilter() {
+ return new CsrfFilter(new HttpSessionCsrfTokenRepository());
+ }
+
+ // Provides automatic CSRF token inclusion when using Spring MVC Form tags or Thymeleaf.
+ // See http://localhost:8080/#forms and form.jsp for examples
+
+ @Bean
+ public RequestDataValueProcessor requestDataValueProcessor() {
+ return new CsrfRequestDataValueProcessor();
+ }
+}
diff --git a/src/main/java/org/springframework/samples/mvc/config/WebMvcConfig.java b/src/main/java/org/springframework/samples/mvc/config/WebMvcConfig.java
new file mode 100644
index 000000000..b73729309
--- /dev/null
+++ b/src/main/java/org/springframework/samples/mvc/config/WebMvcConfig.java
@@ -0,0 +1,80 @@
+package org.springframework.samples.mvc.config;
+
+import java.util.List;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.format.FormatterRegistry;
+import org.springframework.samples.mvc.async.TimeoutCallableProcessingInterceptor;
+import org.springframework.samples.mvc.convert.MaskFormatAnnotationFormatterFactory;
+import org.springframework.samples.mvc.data.custom.CustomArgumentResolver;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.web.method.support.HandlerMethodArgumentResolver;
+import org.springframework.web.multipart.MultipartResolver;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
+import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.util.UrlPathHelper;
+
+// DispatcherServlet context: defines Spring MVC infrastructure
+// and web application components
+
+@Configuration
+@ComponentScan(basePackages = "org.springframework.samples.mvc")
+@EnableWebMvc
+@EnableScheduling
+public class WebMvcConfig implements WebMvcConfigurer {
+
+ @Override
+ public void addFormatters(FormatterRegistry registry) {
+ registry.addFormatterForFieldAnnotation(new MaskFormatAnnotationFormatterFactory());
+ }
+
+ @Override
+ public void addArgumentResolvers(List resolvers) {
+ resolvers.add(new CustomArgumentResolver());
+ }
+
+ // Handle HTTP GET requests for /resources/** by efficiently serving
+ // static resources under ${webappRoot}/resources/
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
+ }
+
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/").setViewName("home");
+ }
+
+ @Override
+ public void configureViewResolvers(ViewResolverRegistry registry) {
+ registry.jsp("/WEB-INF/views/", ".jsp");
+ }
+
+ @Override
+ public void configurePathMatch(PathMatchConfigurer configurer) {
+ UrlPathHelper pathHelper = new UrlPathHelper();
+ pathHelper.setRemoveSemicolonContent(false); // For @MatrixVariable's
+ configurer.setUrlPathHelper(pathHelper);
+ }
+
+ @Override
+ public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
+ configurer.setDefaultTimeout(3000);
+ configurer.registerCallableInterceptors(new TimeoutCallableProcessingInterceptor());
+ }
+
+ @Bean
+ public MultipartResolver multipartResolver() {
+ return new CommonsMultipartResolver();
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/mvc/convert/ConvertController.java b/src/main/java/org/springframework/samples/mvc/convert/ConvertController.java
index 2db688250..09da254ab 100644
--- a/src/main/java/org/springframework/samples/mvc/convert/ConvertController.java
+++ b/src/main/java/org/springframework/samples/mvc/convert/ConvertController.java
@@ -5,49 +5,49 @@
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
-import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
@RequestMapping("/convert")
public class ConvertController {
- @RequestMapping("primitive")
- public @ResponseBody String primitive(@RequestParam Integer value) {
+ @GetMapping("primitive")
+ public String primitive(@RequestParam Integer value) {
return "Converted primitive " + value;
}
// requires Joda-Time on the classpath
- @RequestMapping("date/{value}")
- public @ResponseBody String date(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date value) {
+ @GetMapping("date/{value}")
+ public String date(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date value) {
return "Converted date " + value;
}
- @RequestMapping("collection")
- public @ResponseBody String collection(@RequestParam Collection values) {
+ @GetMapping("collection")
+ public String collection(@RequestParam Collection values) {
return "Converted collection " + values;
}
- @RequestMapping("formattedCollection")
- public @ResponseBody String formattedCollection(@RequestParam @DateTimeFormat(iso=ISO.DATE) Collection values) {
+ @GetMapping("formattedCollection")
+ public String formattedCollection(@RequestParam @DateTimeFormat(iso=ISO.DATE) Collection values) {
return "Converted formatted collection " + values;
}
- @RequestMapping("bean")
- public @ResponseBody String bean(JavaBean bean) {
+ @GetMapping("bean")
+ public String bean(JavaBean bean) {
return "Converted " + bean;
}
- @RequestMapping("value")
- public @ResponseBody String valueObject(@RequestParam SocialSecurityNumber value) {
+ @GetMapping("value")
+ public String valueObject(@RequestParam SocialSecurityNumber value) {
return "Converted value object " + value;
}
- @RequestMapping("custom")
- public @ResponseBody String customConverter(@RequestParam @MaskFormat("###-##-####") String value) {
+ @GetMapping("custom")
+ public String customConverter(@RequestParam @MaskFormat("###-##-####") String value) {
return "Converted '" + value + "' with a custom converter";
}
diff --git a/src/main/java/org/springframework/samples/mvc/data/RequestDataController.java b/src/main/java/org/springframework/samples/mvc/data/RequestDataController.java
index 5919e7cf9..9d0b7e99c 100644
--- a/src/main/java/org/springframework/samples/mvc/data/RequestDataController.java
+++ b/src/main/java/org/springframework/samples/mvc/data/RequestDataController.java
@@ -1,67 +1,67 @@
package org.springframework.samples.mvc.data;
import org.springframework.http.HttpEntity;
-import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.MatrixVariable;
import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
@RequestMapping("/data")
public class RequestDataController {
- @RequestMapping(value="param", method=RequestMethod.GET)
- public @ResponseBody String withParam(@RequestParam String foo) {
+ @GetMapping("param")
+ public String withParam(@RequestParam String foo) {
return "Obtained 'foo' query parameter value '" + foo + "'";
}
- @RequestMapping(value="group", method=RequestMethod.GET)
- public @ResponseBody String withParamGroup(JavaBean bean) {
+ @GetMapping("group")
+ public String withParamGroup(JavaBean bean) {
return "Obtained parameter group " + bean;
}
- @RequestMapping(value="path/{var}", method=RequestMethod.GET)
- public @ResponseBody String withPathVariable(@PathVariable String var) {
+ @GetMapping("path/{var}")
+ public String withPathVariable(@PathVariable String var) {
return "Obtained 'var' path variable value '" + var + "'";
}
- @RequestMapping(value="{path}/simple", method=RequestMethod.GET)
- public @ResponseBody String withMatrixVariable(@PathVariable String path, @MatrixVariable String foo) {
+ @GetMapping("{path}/simple")
+ public String withMatrixVariable(@PathVariable String path, @MatrixVariable String foo) {
return "Obtained matrix variable 'foo=" + foo + "' from path segment '" + path + "'";
}
- @RequestMapping(value="{path1}/{path2}", method=RequestMethod.GET)
- public @ResponseBody String withMatrixVariablesMultiple (
- @PathVariable String path1, @MatrixVariable(value="foo", pathVar="path1") String foo1,
- @PathVariable String path2, @MatrixVariable(value="foo", pathVar="path2") String foo2) {
+ @GetMapping("{path1}/{path2}")
+ public String withMatrixVariablesMultiple (
+ @PathVariable String path1, @MatrixVariable(name="foo", pathVar="path1") String foo1,
+ @PathVariable String path2, @MatrixVariable(name="foo", pathVar="path2") String foo2) {
return "Obtained matrix variable foo=" + foo1 + " from path segment '" + path1
+ "' and variable 'foo=" + foo2 + " from path segment '" + path2 + "'";
}
- @RequestMapping(value="header", method=RequestMethod.GET)
- public @ResponseBody String withHeader(@RequestHeader String Accept) {
+ @GetMapping("header")
+ public String withHeader(@RequestHeader String Accept) {
return "Obtained 'Accept' header '" + Accept + "'";
}
- @RequestMapping(value="cookie", method=RequestMethod.GET)
- public @ResponseBody String withCookie(@CookieValue String openid_provider) {
+ @GetMapping("cookie")
+ public String withCookie(@CookieValue String openid_provider) {
return "Obtained 'openid_provider' cookie '" + openid_provider + "'";
}
- @RequestMapping(value="body", method=RequestMethod.POST)
- public @ResponseBody String withBody(@RequestBody String body) {
+ @PostMapping("body")
+ public String withBody(@RequestBody String body) {
return "Posted request body '" + body + "'";
}
- @RequestMapping(value="entity", method=RequestMethod.POST)
- public @ResponseBody String withEntity(HttpEntity entity) {
+ @PostMapping("entity")
+ public String withEntity(HttpEntity entity) {
return "Posted request body '" + entity.getBody() + "'; headers = " + entity.getHeaders();
}
diff --git a/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentController.java b/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentController.java
index 3f3d4748b..66368fa34 100644
--- a/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentController.java
+++ b/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentController.java
@@ -2,13 +2,11 @@
import javax.servlet.http.HttpServletRequest;
-import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
public class CustomArgumentController {
@ModelAttribute
@@ -16,8 +14,8 @@ void beforeInvokingHandlerMethod(HttpServletRequest request) {
request.setAttribute("foo", "bar");
}
- @RequestMapping(value="/data/custom", method=RequestMethod.GET)
- public @ResponseBody String custom(@RequestAttribute("foo") String foo) {
+ @GetMapping("/data/custom")
+ public String custom(@RequestAttribute("foo") String foo) {
return "Got 'foo' request attribute value '" + foo + "'";
}
diff --git a/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentResolver.java b/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentResolver.java
index ed1b02fcc..59ba7fbf6 100644
--- a/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentResolver.java
+++ b/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentResolver.java
@@ -13,8 +13,10 @@ public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterAnnotation(RequestAttribute.class) != null;
}
- public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
- WebDataBinderFactory binderFactory) throws Exception {
+ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
+ NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
+ throws Exception {
+
RequestAttribute attr = parameter.getParameterAnnotation(RequestAttribute.class);
return webRequest.getAttribute(attr.value(), WebRequest.SCOPE_REQUEST);
}
diff --git a/src/main/java/org/springframework/samples/mvc/data/standard/StandardArgumentsController.java b/src/main/java/org/springframework/samples/mvc/data/standard/StandardArgumentsController.java
index 4059b7f10..c5276ae91 100644
--- a/src/main/java/org/springframework/samples/mvc/data/standard/StandardArgumentsController.java
+++ b/src/main/java/org/springframework/samples/mvc/data/standard/StandardArgumentsController.java
@@ -7,24 +7,22 @@
import java.io.Writer;
import java.security.Principal;
import java.util.Locale;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
public class StandardArgumentsController {
// request related
- @RequestMapping(value="/data/standard/request", method=RequestMethod.GET)
- public @ResponseBody String standardRequestArgs(HttpServletRequest request, Principal user, Locale locale) {
+ @GetMapping("/data/standard/request")
+ public String standardRequestArgs(HttpServletRequest request, Principal user, Locale locale) {
StringBuilder buffer = new StringBuilder();
buffer.append("request = ").append(request).append(", ");
buffer.append("userPrincipal = ").append(user).append(", ");
@@ -32,37 +30,37 @@ public class StandardArgumentsController {
return buffer.toString();
}
- @RequestMapping(value="/data/standard/request/reader", method=RequestMethod.POST)
- public @ResponseBody String requestReader(Reader requestBodyReader) throws IOException {
+ @PostMapping("/data/standard/request/reader")
+ public String requestReader(Reader requestBodyReader) throws IOException {
return "Read char request body = " + FileCopyUtils.copyToString(requestBodyReader);
}
- @RequestMapping(value="/data/standard/request/is", method=RequestMethod.POST)
- public @ResponseBody String requestReader(InputStream requestBodyIs) throws IOException {
+ @PostMapping("/data/standard/request/is")
+ public String requestReader(InputStream requestBodyIs) throws IOException {
return "Read binary request body = " + new String(FileCopyUtils.copyToByteArray(requestBodyIs));
}
// response related
- @RequestMapping("/data/standard/response")
- public @ResponseBody String response(HttpServletResponse response) {
+ @GetMapping("/data/standard/response")
+ public String response(HttpServletResponse response) {
return "response = " + response;
}
- @RequestMapping("/data/standard/response/writer")
+ @GetMapping("/data/standard/response/writer")
public void availableStandardResponseArguments(Writer responseWriter) throws IOException {
responseWriter.write("Wrote char response using Writer");
}
- @RequestMapping("/data/standard/response/os")
+ @GetMapping("/data/standard/response/os")
public void availableStandardResponseArguments(OutputStream os) throws IOException {
os.write("Wrote binary response using OutputStream".getBytes());
}
// HttpSession
- @RequestMapping("/data/standard/session")
- public @ResponseBody String session(HttpSession session) {
+ @GetMapping("/data/standard/session")
+ public String session(HttpSession session) {
StringBuilder buffer = new StringBuilder();
buffer.append("session=").append(session);
return buffer.toString();
diff --git a/src/main/java/org/springframework/samples/mvc/exceptions/ExceptionController.java b/src/main/java/org/springframework/samples/mvc/exceptions/ExceptionController.java
index 8db32b5b0..7b3e0d616 100644
--- a/src/main/java/org/springframework/samples/mvc/exceptions/ExceptionController.java
+++ b/src/main/java/org/springframework/samples/mvc/exceptions/ExceptionController.java
@@ -1,25 +1,24 @@
package org.springframework.samples.mvc.exceptions;
-import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
public class ExceptionController {
- @RequestMapping("/exception")
- public @ResponseBody String exception() {
+ @GetMapping("/exception")
+ public String exception() {
throw new IllegalStateException("Sorry!");
}
- @RequestMapping("/global-exception")
- public @ResponseBody String businessException() throws BusinessException {
+ @GetMapping("/global-exception")
+ public String businessException() throws BusinessException {
throw new BusinessException();
}
@ExceptionHandler
- public @ResponseBody String handle(IllegalStateException e) {
+ public String handle(IllegalStateException e) {
return "IllegalStateException handled!";
}
diff --git a/src/main/java/org/springframework/samples/mvc/exceptions/GlobalExceptionHandler.java b/src/main/java/org/springframework/samples/mvc/exceptions/GlobalExceptionHandler.java
index f50339790..10d5da8ce 100644
--- a/src/main/java/org/springframework/samples/mvc/exceptions/GlobalExceptionHandler.java
+++ b/src/main/java/org/springframework/samples/mvc/exceptions/GlobalExceptionHandler.java
@@ -1,14 +1,13 @@
package org.springframework.samples.mvc.exceptions;
-import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
-@ControllerAdvice
+@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler
- public @ResponseBody String handleBusinessException(BusinessException ex) {
+ public String handleBusinessException(BusinessException ex) {
return "Handled BusinessException";
}
diff --git a/src/main/java/org/springframework/samples/mvc/fileupload/FileUploadController.java b/src/main/java/org/springframework/samples/mvc/fileupload/FileUploadController.java
index b7eda699d..b49489a3c 100644
--- a/src/main/java/org/springframework/samples/mvc/fileupload/FileUploadController.java
+++ b/src/main/java/org/springframework/samples/mvc/fileupload/FileUploadController.java
@@ -1,13 +1,12 @@
package org.springframework.samples.mvc.fileupload;
-import java.io.IOException;
-
import org.springframework.mvc.extensions.ajax.AjaxUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.multipart.MultipartFile;
@@ -21,12 +20,12 @@ public void ajaxAttribute(WebRequest request, Model model) {
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(request));
}
- @RequestMapping(method=RequestMethod.GET)
+ @GetMapping
public void fileUploadForm() {
}
- @RequestMapping(method=RequestMethod.POST)
- public void processUpload(@RequestParam MultipartFile file, Model model) throws IOException {
+ @PostMapping
+ public void processUpload(@RequestParam MultipartFile file, Model model) {
model.addAttribute("message", "File '" + file.getOriginalFilename() + "' uploaded successfully");
}
diff --git a/src/main/java/org/springframework/samples/mvc/form/FormController.java b/src/main/java/org/springframework/samples/mvc/form/FormController.java
index a5b396976..b5837b9fe 100644
--- a/src/main/java/org/springframework/samples/mvc/form/FormController.java
+++ b/src/main/java/org/springframework/samples/mvc/form/FormController.java
@@ -6,9 +6,10 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@@ -33,11 +34,11 @@ public FormBean createFormBean() {
return new FormBean();
}
- @RequestMapping(method=RequestMethod.GET)
+ @GetMapping
public void form() {
}
- @RequestMapping(method=RequestMethod.POST)
+ @PostMapping
public String processSubmit(@Valid FormBean formBean, BindingResult result,
@ModelAttribute("ajaxRequest") boolean ajaxRequest,
Model model, RedirectAttributes redirectAttrs) {
diff --git a/src/main/java/org/springframework/samples/mvc/mapping/ClasslevelMappingController.java b/src/main/java/org/springframework/samples/mvc/mapping/ClasslevelMappingController.java
index d131a9cf4..dafa6d1a3 100644
--- a/src/main/java/org/springframework/samples/mvc/mapping/ClasslevelMappingController.java
+++ b/src/main/java/org/springframework/samples/mvc/mapping/ClasslevelMappingController.java
@@ -2,59 +2,59 @@
import javax.servlet.http.HttpServletRequest;
-import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
@RequestMapping("/class-mapping/*")
public class ClasslevelMappingController {
- @RequestMapping("/path")
- public @ResponseBody String byPath() {
+ @GetMapping("/path")
+ public String byPath() {
return "Mapped by path!";
}
- @RequestMapping(value="/path/*", method=RequestMethod.GET)
- public @ResponseBody String byPathPattern(HttpServletRequest request) {
+ @GetMapping("/path/*")
+ public String byPathPattern(HttpServletRequest request) {
return "Mapped by path pattern ('" + request.getRequestURI() + "')";
}
- @RequestMapping(value="/method", method=RequestMethod.GET)
- public @ResponseBody String byMethod() {
+ @GetMapping("/method")
+ public String byMethod() {
return "Mapped by path + method";
}
- @RequestMapping(value="/parameter", method=RequestMethod.GET, params="foo")
- public @ResponseBody String byParameter() {
+ @GetMapping(path="/parameter", params="foo")
+ public String byParameter() {
return "Mapped by path + method + presence of query parameter!";
}
- @RequestMapping(value="/parameter", method=RequestMethod.GET, params="!foo")
- public @ResponseBody String byParameterNegation() {
+ @GetMapping(path="/parameter", params="!foo")
+ public String byParameterNegation() {
return "Mapped by path + method + not presence of query!";
}
- @RequestMapping(value="/header", method=RequestMethod.GET, headers="FooHeader=foo")
- public @ResponseBody String byHeader() {
+ @GetMapping(path="/header", headers="FooHeader=foo")
+ public String byHeader() {
return "Mapped by path + method + presence of header!";
}
- @RequestMapping(value="/notheader", method=RequestMethod.GET, headers="!FooHeader")
- public @ResponseBody String byHeaderNegation() {
+ @GetMapping(path="/notheader", headers="!FooHeader")
+ public String byHeaderNegation() {
return "Mapped by path + method + absence of header!";
}
- @RequestMapping(value="/consumes", method=RequestMethod.POST, consumes="application/json")
- public @ResponseBody String byConsumes(@RequestBody JavaBean javaBean) {
+ @PostMapping(path="/consumes", consumes="application/json")
+ public String byConsumes(@RequestBody JavaBean javaBean) {
return "Mapped by path + method + consumable media type (javaBean '" + javaBean + "')";
}
- @RequestMapping(value="/produces", method=RequestMethod.GET, produces="application/json")
- public @ResponseBody JavaBean byProduces() {
+ @GetMapping(path="/produces", produces="application/json")
+ public JavaBean byProduces() {
return new JavaBean();
}
diff --git a/src/main/java/org/springframework/samples/mvc/mapping/MappingController.java b/src/main/java/org/springframework/samples/mvc/mapping/MappingController.java
index cbebdcbe2..823d9ad0b 100644
--- a/src/main/java/org/springframework/samples/mvc/mapping/MappingController.java
+++ b/src/main/java/org/springframework/samples/mvc/mapping/MappingController.java
@@ -3,62 +3,61 @@
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.MediaType;
-import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
public class MappingController {
- @RequestMapping("/mapping/path")
- public @ResponseBody String byPath() {
+ @GetMapping("/mapping/path")
+ public String byPath() {
return "Mapped by path!";
}
- @RequestMapping(value="/mapping/path/*", method=RequestMethod.GET)
- public @ResponseBody String byPathPattern(HttpServletRequest request) {
+ @GetMapping("/mapping/path/*")
+ public String byPathPattern(HttpServletRequest request) {
return "Mapped by path pattern ('" + request.getRequestURI() + "')";
}
- @RequestMapping(value="/mapping/method", method=RequestMethod.GET)
- public @ResponseBody String byMethod() {
+ @GetMapping("/mapping/method")
+ public String byMethod() {
return "Mapped by path + method";
}
- @RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="foo")
- public @ResponseBody String byParameter() {
+ @GetMapping(path="/mapping/parameter", params="foo")
+ public String byParameter() {
return "Mapped by path + method + presence of query parameter!";
}
- @RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="!foo")
- public @ResponseBody String byParameterNegation() {
+ @GetMapping(path="/mapping/parameter", params="!foo")
+ public String byParameterNegation() {
return "Mapped by path + method + not presence of query parameter!";
}
- @RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="FooHeader=foo")
- public @ResponseBody String byHeader() {
+ @GetMapping(path="/mapping/header", headers="FooHeader=foo")
+ public String byHeader() {
return "Mapped by path + method + presence of header!";
}
- @RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="!FooHeader")
- public @ResponseBody String byHeaderNegation() {
+ @GetMapping(path="/mapping/header", headers="!FooHeader")
+ public String byHeaderNegation() {
return "Mapped by path + method + absence of header!";
}
- @RequestMapping(value="/mapping/consumes", method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE)
- public @ResponseBody String byConsumes(@RequestBody JavaBean javaBean) {
+ @PostMapping(path="/mapping/consumes", consumes=MediaType.APPLICATION_JSON_VALUE)
+ public String byConsumes(@RequestBody JavaBean javaBean) {
return "Mapped by path + method + consumable media type (javaBean '" + javaBean + "')";
}
- @RequestMapping(value="/mapping/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
- public @ResponseBody JavaBean byProducesJson() {
+ @GetMapping(path="/mapping/produces", produces=MediaType.APPLICATION_JSON_VALUE)
+ public JavaBean byProducesJson() {
return new JavaBean();
}
- @RequestMapping(value="/mapping/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_XML_VALUE)
- public @ResponseBody JavaBean byProducesXml() {
+ @GetMapping(path="/mapping/produces", produces=MediaType.APPLICATION_XML_VALUE)
+ public JavaBean byProducesXml() {
return new JavaBean();
}
diff --git a/src/main/java/org/springframework/samples/mvc/messageconverters/MessageConvertersController.java b/src/main/java/org/springframework/samples/mvc/messageconverters/MessageConvertersController.java
index 47da6ee95..780e67df5 100644
--- a/src/main/java/org/springframework/samples/mvc/messageconverters/MessageConvertersController.java
+++ b/src/main/java/org/springframework/samples/mvc/messageconverters/MessageConvertersController.java
@@ -5,40 +5,41 @@
import com.rometools.rome.feed.atom.Feed;
import com.rometools.rome.feed.rss.Channel;
-import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
@RequestMapping("/messageconverters")
public class MessageConvertersController {
// StringHttpMessageConverter
- @RequestMapping(value="/string", method=RequestMethod.POST)
- public @ResponseBody String readString(@RequestBody String string) {
+ @PostMapping("/string")
+ public String readString(@RequestBody String string) {
return "Read string '" + string + "'";
}
- @RequestMapping(value="/string", method=RequestMethod.GET)
- public @ResponseBody String writeString() {
+ @GetMapping("/string")
+ public String writeString() {
return "Wrote a string";
}
// Form encoded data (application/x-www-form-urlencoded)
- @RequestMapping(value="/form", method=RequestMethod.POST)
- public @ResponseBody String readForm(@ModelAttribute JavaBean bean) {
+ @PostMapping("/form")
+ public String readForm(@ModelAttribute JavaBean bean) {
return "Read x-www-form-urlencoded: " + bean;
}
- @RequestMapping(value="/form", method=RequestMethod.GET)
- public @ResponseBody MultiValueMap writeForm() {
+ @GetMapping("/form")
+ public MultiValueMap writeForm() {
MultiValueMap map = new LinkedMultiValueMap();
map.add("foo", "bar");
map.add("fruit", "apple");
@@ -47,37 +48,37 @@ public class MessageConvertersController {
// Jaxb2RootElementHttpMessageConverter (requires JAXB2 on the classpath - useful for serving clients that expect to work with XML)
- @RequestMapping(value="/xml", method=RequestMethod.POST)
- public @ResponseBody String readXml(@RequestBody JavaBean bean) {
+ @PostMapping("/xml")
+ public String readXml(@RequestBody JavaBean bean) {
return "Read from XML: " + bean;
}
- @RequestMapping(value="/xml", method=RequestMethod.GET)
- public @ResponseBody JavaBean writeXml() {
+ @GetMapping("/xml")
+ public JavaBean writeXml() {
return new JavaBean("bar", "apple");
}
// MappingJacksonHttpMessageConverter (requires Jackson on the classpath - particularly useful for serving JavaScript clients that expect to work with JSON)
- @RequestMapping(value="/json", method=RequestMethod.POST)
- public @ResponseBody String readJson(@Valid @RequestBody JavaBean bean) {
+ @PostMapping("/json")
+ public String readJson(@Valid @RequestBody JavaBean bean) {
return "Read from JSON: " + bean;
}
- @RequestMapping(value="/json", method=RequestMethod.GET)
- public @ResponseBody JavaBean writeJson() {
+ @GetMapping("/json")
+ public JavaBean writeJson() {
return new JavaBean("bar", "apple");
}
// AtomFeedHttpMessageConverter (requires Rome on the classpath - useful for serving Atom feeds)
- @RequestMapping(value="/atom", method=RequestMethod.POST)
- public @ResponseBody String readFeed(@RequestBody Feed feed) {
+ @PostMapping("/atom")
+ public String readFeed(@RequestBody Feed feed) {
return "Read " + feed.getTitle();
}
- @RequestMapping(value="/atom", method=RequestMethod.GET)
- public @ResponseBody Feed writeFeed() {
+ @GetMapping("/atom")
+ public Feed writeFeed() {
Feed feed = new Feed();
feed.setFeedType("atom_1.0");
feed.setTitle("My Atom feed");
@@ -86,13 +87,13 @@ public class MessageConvertersController {
// RssChannelHttpMessageConverter (requires Rome on the classpath - useful for serving RSS feeds)
- @RequestMapping(value="/rss", method=RequestMethod.POST)
- public @ResponseBody String readChannel(@RequestBody Channel channel) {
+ @PostMapping("/rss")
+ public String readChannel(@RequestBody Channel channel) {
return "Read " + channel.getTitle();
}
- @RequestMapping(value="/rss", method=RequestMethod.GET)
- public @ResponseBody Channel writeChannel() {
+ @GetMapping("/rss")
+ public Channel writeChannel() {
Channel channel = new Channel();
channel.setFeedType("rss_2.0");
channel.setTitle("My RSS feed");
diff --git a/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java b/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java
index c34470592..174b6b68e 100644
--- a/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java
+++ b/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java
@@ -3,11 +3,12 @@
import javax.inject.Inject;
import org.joda.time.LocalDate;
+
import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.util.UriComponents;
@@ -24,14 +25,14 @@ public RedirectController(ConversionService conversionService) {
this.conversionService = conversionService;
}
- @RequestMapping(value="/uriTemplate", method=RequestMethod.GET)
+ @GetMapping("/uriTemplate")
public String uriTemplate(RedirectAttributes redirectAttrs) {
redirectAttrs.addAttribute("account", "a123"); // Used as URI template variable
redirectAttrs.addAttribute("date", new LocalDate(2011, 12, 31)); // Appended as a query parameter
return "redirect:/redirect/{account}";
}
- @RequestMapping(value="/uriComponentsBuilder", method=RequestMethod.GET)
+ @GetMapping("/uriComponentsBuilder")
public String uriComponentsBuilder() {
String date = this.conversionService.convert(new LocalDate(2011, 12, 31), String.class);
UriComponents redirectUri = UriComponentsBuilder.fromPath("/redirect/{account}").queryParam("date", date)
@@ -39,7 +40,7 @@ public String uriComponentsBuilder() {
return "redirect:" + redirectUri.toUriString();
}
- @RequestMapping(value="/{account}", method=RequestMethod.GET)
+ @GetMapping("/{account}")
public String show(@PathVariable String account, @RequestParam(required=false) LocalDate date) {
return "redirect/redirectResults";
}
diff --git a/src/main/java/org/springframework/samples/mvc/response/ResponseController.java b/src/main/java/org/springframework/samples/mvc/response/ResponseController.java
index 22e15ff83..ef95195ac 100644
--- a/src/main/java/org/springframework/samples/mvc/response/ResponseController.java
+++ b/src/main/java/org/springframework/samples/mvc/response/ResponseController.java
@@ -4,37 +4,37 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
@RequestMapping(value="/response", method=RequestMethod.GET)
public class ResponseController {
- @RequestMapping("/annotation")
- public @ResponseBody String responseBody() {
+ @GetMapping("/annotation")
+ public String responseBody() {
return "The String ResponseBody";
}
- @RequestMapping("/charset/accept")
- public @ResponseBody String responseAcceptHeaderCharset() {
+ @GetMapping("/charset/accept")
+ public String responseAcceptHeaderCharset() {
return "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)";
}
- @RequestMapping(value="/charset/produce", produces="text/plain;charset=UTF-8")
- public @ResponseBody String responseProducesConditionCharset() {
+ @GetMapping(value="/charset/produce", produces="text/plain;charset=UTF-8")
+ public String responseProducesConditionCharset() {
return "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)";
}
- @RequestMapping("/entity/status")
+ @GetMapping("/entity/status")
public ResponseEntity responseEntityStatusCode() {
return new ResponseEntity("The String ResponseBody with custom status code (403 Forbidden)",
HttpStatus.FORBIDDEN);
}
- @RequestMapping("/entity/headers")
+ @GetMapping("/entity/headers")
public ResponseEntity responseEntityCustomHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
diff --git a/src/main/java/org/springframework/samples/mvc/simple/SimpleController.java b/src/main/java/org/springframework/samples/mvc/simple/SimpleController.java
index eb37c30e5..7c9bfa278 100644
--- a/src/main/java/org/springframework/samples/mvc/simple/SimpleController.java
+++ b/src/main/java/org/springframework/samples/mvc/simple/SimpleController.java
@@ -1,14 +1,13 @@
package org.springframework.samples.mvc.simple;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
public class SimpleController {
- @RequestMapping("/simple")
- public @ResponseBody String simple() {
+ @GetMapping("/simple")
+ public String simple() {
return "Hello world!";
}
diff --git a/src/main/java/org/springframework/samples/mvc/simple/SimpleControllerRevisited.java b/src/main/java/org/springframework/samples/mvc/simple/SimpleControllerRevisited.java
index 67efe40f9..fb9889ce4 100644
--- a/src/main/java/org/springframework/samples/mvc/simple/SimpleControllerRevisited.java
+++ b/src/main/java/org/springframework/samples/mvc/simple/SimpleControllerRevisited.java
@@ -1,15 +1,13 @@
package org.springframework.samples.mvc.simple;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
public class SimpleControllerRevisited {
- @RequestMapping(value="/simple/revisited", method=RequestMethod.GET, headers="Accept=text/plain")
- public @ResponseBody String simple() {
+ @GetMapping(path="/simple/revisited", headers="Accept=text/plain")
+ public String simple() {
return "Hello world revisited!";
}
diff --git a/src/main/java/org/springframework/samples/mvc/validation/ValidationController.java b/src/main/java/org/springframework/samples/mvc/validation/ValidationController.java
index 6384e3065..4a916d5b7 100644
--- a/src/main/java/org/springframework/samples/mvc/validation/ValidationController.java
+++ b/src/main/java/org/springframework/samples/mvc/validation/ValidationController.java
@@ -4,16 +4,16 @@
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
public class ValidationController {
// enforcement of constraints on the JavaBean arg require a JSR-303 provider on the classpath
- @RequestMapping("/validate")
- public @ResponseBody String validate(@Valid JavaBean bean, BindingResult result) {
+ @GetMapping("/validate")
+ public String validate(@Valid JavaBean bean, BindingResult result) {
if (result.hasErrors()) {
return "Object has validation errors";
} else {
diff --git a/src/main/java/org/springframework/samples/mvc/views/ViewsController.java b/src/main/java/org/springframework/samples/mvc/views/ViewsController.java
index d8ce95f8e..b1f9ab1b2 100644
--- a/src/main/java/org/springframework/samples/mvc/views/ViewsController.java
+++ b/src/main/java/org/springframework/samples/mvc/views/ViewsController.java
@@ -4,35 +4,35 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/views/*")
public class ViewsController {
- @RequestMapping(value="html", method=RequestMethod.GET)
+ @GetMapping("html")
public String prepare(Model model) {
model.addAttribute("foo", "bar");
model.addAttribute("fruit", "apple");
return "views/html";
}
- @RequestMapping(value="/viewName", method=RequestMethod.GET)
+ @GetMapping("/viewName")
public void usingRequestToViewNameTranslator(Model model) {
model.addAttribute("foo", "bar");
model.addAttribute("fruit", "apple");
}
- @RequestMapping(value="pathVariables/{foo}/{fruit}", method=RequestMethod.GET)
+ @GetMapping("pathVariables/{foo}/{fruit}")
public String pathVars(@PathVariable String foo, @PathVariable String fruit) {
// No need to add @PathVariables "foo" and "fruit" to the model
// They will be merged in the model before rendering
return "views/html";
}
- @RequestMapping(value="dataBinding/{foo}/{fruit}", method=RequestMethod.GET)
+ @GetMapping("dataBinding/{foo}/{fruit}")
public String dataBinding(@Valid JavaBean javaBean, Model model) {
// JavaBean "foo" and "fruit" properties populated from URI variables
return "views/dataBinding";
diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml
deleted file mode 100644
index 5439a479f..000000000
--- a/src/main/resources/log4j.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
new file mode 100644
index 000000000..da5e62170
--- /dev/null
+++ b/src/main/resources/log4j2.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml b/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml
deleted file mode 100644
index 56dba6e8c..000000000
--- a/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
deleted file mode 100644
index eb46e018b..000000000
--- a/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml
deleted file mode 100644
index 2c734abb4..000000000
--- a/src/main/webapp/WEB-INF/spring/root-context.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/webapp/WEB-INF/views/fileupload.jsp b/src/main/webapp/WEB-INF/views/fileupload.jsp
index 05534b222..0b54e1d9b 100644
--- a/src/main/webapp/WEB-INF/views/fileupload.jsp
+++ b/src/main/webapp/WEB-INF/views/fileupload.jsp
@@ -16,7 +16,7 @@