From a91402dcc6402e7d0e291fabc38d22fd86da3519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 19 Jan 2026 14:20:44 +0100 Subject: [PATCH] Extract code snippets from multipart.adoc See gh-36175 --- .../web/webmvc/mvc-servlet/multipart.adoc | 38 +------------- .../AppInitializer.java | 52 +++++++++++++++++++ .../AppInitializer.kt | 48 +++++++++++++++++ 3 files changed, 101 insertions(+), 37 deletions(-) create mode 100644 framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcservlet/mvcmultipartresolverstandard/AppInitializer.java create mode 100644 framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcservlet/mvcmultipartresolverstandard/AppInitializer.kt diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-servlet/multipart.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-servlet/multipart.adoc index cdf564f281d..23febfb6ba6 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-servlet/multipart.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-servlet/multipart.adoc @@ -26,43 +26,7 @@ To do so: The following example shows how to set a `MultipartConfigElement` on the Servlet registration: -[tabs] -====== -Java:: -+ -[source,java,indent=0,subs="verbatim,quotes"] ----- - public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - // ... - - @Override - protected void customizeRegistration(ServletRegistration.Dynamic registration) { - - // Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold - registration.setMultipartConfig(new MultipartConfigElement("/tmp")); - } - - } ----- - -Kotlin:: -+ -[source,kotlin,indent=0,subs="verbatim,quotes"] ----- - class AppInitializer : AbstractAnnotationConfigDispatcherServletInitializer() { - - // ... - - override fun customizeRegistration(registration: ServletRegistration.Dynamic) { - - // Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold - registration.setMultipartConfig(MultipartConfigElement("/tmp")) - } - - } ----- -====== +include-code::./AppInitializer[tag=snippet,indent=0] Once the Servlet multipart configuration is in place, you can add a bean of type `StandardServletMultipartResolver` with a name of `multipartResolver`. diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcservlet/mvcmultipartresolverstandard/AppInitializer.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcservlet/mvcmultipartresolverstandard/AppInitializer.java new file mode 100644 index 00000000000..bca92acec59 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcservlet/mvcmultipartresolverstandard/AppInitializer.java @@ -0,0 +1,52 @@ +/* + * Copyright 2002-2025 the original author or authors. + * + * 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 + * + * https://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. + */ + +package org.springframework.docs.web.webmvc.mvcservlet.mvcmultipartresolverstandard; + +import jakarta.servlet.MultipartConfigElement; +import jakarta.servlet.ServletRegistration; +import org.jspecify.annotations.Nullable; + +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +// tag::snippet[] +public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { + + // @fold:on + @Override + protected String[] getServletMappings() { + /**/throw new UnsupportedOperationException(); + } + + @Override + protected Class @Nullable [] getRootConfigClasses() { + /**/throw new UnsupportedOperationException(); + } + + @Override + protected Class @Nullable [] getServletConfigClasses() { + /**/throw new UnsupportedOperationException(); + } + + // @fold:off + @Override + protected void customizeRegistration(ServletRegistration.Dynamic registration) { + + // Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold + registration.setMultipartConfig(new MultipartConfigElement("/tmp")); + } +} +// end::snippet[] diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcservlet/mvcmultipartresolverstandard/AppInitializer.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcservlet/mvcmultipartresolverstandard/AppInitializer.kt new file mode 100644 index 00000000000..ee0669e5f97 --- /dev/null +++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcservlet/mvcmultipartresolverstandard/AppInitializer.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2002-2025 the original author or authors. + * + * 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 + * + * https://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. + */ + +package org.springframework.docs.web.webmvc.mvcservlet.mvcmultipartresolverstandard + +import jakarta.servlet.MultipartConfigElement +import jakarta.servlet.ServletRegistration + +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer + +// tag::snippet[] +class AppInitializer : AbstractAnnotationConfigDispatcherServletInitializer() { + + // @fold:on + override fun getServletMappings(): Array { + /**/TODO("Not yet implemented") + } + + override fun getRootConfigClasses(): Array>? { + /**/TODO("Not yet implemented") + } + + override fun getServletConfigClasses(): Array>? { + /**/TODO("Not yet implemented") + } + + // @fold:off + override fun customizeRegistration(registration: ServletRegistration.Dynamic) { + + // Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold + registration.setMultipartConfig(MultipartConfigElement("/tmp")) + } + +} +// end::snippet[]