161 Spring Boot 3 Real-World Examples to Supercharge Your Backend Development
This article presents a free, continuously updated PDF collection of 161 Spring Boot 3 practical cases that demonstrate core utility classes, complete code snippets, and expected outputs, helping backend developers quickly master common Spring tools and patterns.
Introduction
Spring Boot 3.4.2 based collection of 161 practical cases, continuously updated and freely available as a PDF.
Utility Classes and Code Samples
2.1 AntPathMatcher
Matches strings against Ant‑style path patterns, useful for URL routing and security configuration.
AntPathMatcher matcher = new AntPathMatcher();
boolean match1 = matcher.match("/users/*", "/users/123");
boolean match2 = matcher.match("/users/**", "/users/123/orders");
boolean match3 = matcher.match("/user?", "/user1");
Map<String, String> vars = matcher.extractUriTemplateVariables("/users/{id}", "/users/42");
System.err.printf("match1 = %s, match2 = %s, match3 = %s, vars = %s%n", match1, match2, match3, vars);Output:
match1 = true, match2 = true, match3 = true, vars = {id=42}2.2 PatternMatchUtils
Provides simple wildcard pattern matching methods.
boolean match1 = PatternMatchUtils.simpleMatch("user*", "username");
boolean match2 = PatternMatchUtils.simpleMatch("user?", "user1");
boolean match3 = PatternMatchUtils.simpleMatch(new String[]{"user*", "admin*"}, "adminuser");
System.err.printf("match1 = %s, match2 = %s, match3 = %s%n", match1, match2, match3);Output:
match1 = true, match2 = false, match3 = true2.3 PropertyPlaceholderHelper
Resolves placeholders like ${name} in strings using a given property source.
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
Properties props = new Properties();
props.setProperty("name", "Spring Boot3实战案例200讲");
props.setProperty("title", "标题:${name}!");
String result = helper.replacePlaceholders("${title}", props::getProperty);
System.err.printf("result = %s%n", result);Output:
result = 标题:Spring Boot3实战案例200讲!2.4 MultiValueMap
Extended Map allowing multiple values per key.
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("colors", "red");
map.add("colors", "blue");
map.add("sizes", "large");
List<String> colors = map.get("colors");
System.err.printf("colors: %s%n", colors);Output:
colors: [red, blue]2.5 ConcurrentReferenceHashMap
Thread‑safe map based on soft references, suitable for cache scenarios.
// Create a high‑concurrency cache map
Map<String, Object> cache = new ConcurrentReferenceHashMap<>();
// Value can be reclaimed when memory is low
cache.put("key", new Object());2.6 SystemPropertyUtils
Resolves placeholders using JVM system properties.
String javaHome = SystemPropertyUtils.resolvePlaceholders("${java.home}");
String defaultValue = SystemPropertyUtils.resolvePlaceholders("${unknown.property:default_value}");
System.err.printf("javaHome: %s, defaultValue = %s%n", javaHome, defaultValue);Output:
javaHome: D:\jdk-21.0.1, defaultValue = default_value2.7 ReflectionUtils
Utility for low‑level reflection tasks.
UserDTO dto = new UserDTO();
Field field = ReflectionUtils.findField(UserDTO.class, "name");
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, dto, "John");
Method method = ReflectionUtils.findMethod(UserDTO.class, "setAge", int.class);
ReflectionUtils.invokeMethod(method, dto, 30);2.8 MethodInvoker
Conveniently prepares and invokes a method with arguments.
MethodInvoker invoker = new MethodInvoker();
invoker.setTargetObject(new UserDTO());
invoker.setTargetMethod("calcAge");
invoker.setArguments(100, 0.2);
invoker.prepare();
Object result = invoker.invoke();2.9 ResourceUtils
Loads resources from classpath or URLs.
File file = ResourceUtils.getFile("classpath:config.properties");
boolean isUrl = ResourceUtils.isUrl("http://example.com");
URL url = ResourceUtils.getURL("classpath:data.json");
System.err.printf("file = %s, isUrl = %s, url = %s%n", file, isUrl, url);2.10 WebUtils
Utilities for web‑related tasks such as retrieving cookies or request parameters.
HttpServletRequest request = null;
Cookie cookie = WebUtils.getCookie(request, "sessionId");
String id = WebUtils.findParameterValue(request, "id");2.11 UriUtils
Encodes and decodes URI components per RFC 3986.
String encoded = UriUtils.encodePathSegment("path with spaces", StandardCharsets.UTF_8);
String decoded = UriUtils.decode(encoded, StandardCharsets.UTF_8);
System.err.printf("encoded: %s, decoded = %s%n", encoded, decoded);Output:
encoded: path%20with%20spaces, decoded = path with spaces2.12 UriComponentsBuilder
Fluent builder for constructing URIs.
URI uri = UriComponentsBuilder.fromUriString("https://www.pack.com")
.path("/products/{id}")
.queryParam("category", "books")
.build("123");
System.err.println(uri);Output:
https://www.pack.com/products/123?category=books2.13 HtmlUtils
Escapes and unescapes HTML to prevent XSS.
String escaped = HtmlUtils.htmlEscape("<script>alert('XSS')</script>");
System.err.println(escaped);
String unescaped = HtmlUtils.htmlUnescape("<b>Bold</b>");
System.err.println(unescaped);Output: <script>alert('XSS')</script> and
<b>Bold</b>2.14 ObjectUtils
Null‑safe utilities for objects, arrays, and collections.
boolean isEmpty1 = ObjectUtils.isEmpty(null);
boolean isEmpty2 = ObjectUtils.isEmpty(new int[0]);
Object obj1 = null;
Object obj2 = new Object();
boolean equals = ObjectUtils.nullSafeEquals(obj1, obj2);
System.err.printf("isEmpty1 = %s, isEmpty2 = %s, equals = %s%n", isEmpty1, isEmpty2, equals);Output:
isEmpty1 = true, isEmpty2 = true, equals = false2.15 DateFormatter
Flexible formatter for java.util.Date.
DateFormatter formatter = new DateFormatter("yyyy-MM-dd HH:mm:ss");
String result = formatter.print(new Date(), Locale.getDefault());
System.err.println(result);Sample output:
2025-08-16 09:11:572.16 JsonParserFactory
Factory for obtaining a lightweight JSON parser.
JsonParser parser = JsonParserFactory.getJsonParser();
Map<String, Object> map = parser.parseMap("{\"name\":\"Spring Boot3实战案例200讲\",\"age\":33}");
List<Object> list = parser.parseList("[1, 2, 3]");
System.err.printf("map = %s, list = %s%n", map, list);Output:
map = {name=Spring Boot3实战案例200讲, age=33}, list = [1, 2, 3]2.17 ResolvableType
Handles complex generic types at runtime.
private List<UserDTO> list = new ArrayList<>();
public static void main(String[] args) throws Exception {
ResolvableType listType = ResolvableType.forField(ResolvableTypeTest.class.getDeclaredField("list"));
ResolvableType elementType = listType.getGeneric(0);
ResolvableType mapType = ResolvableType.forClassWithGenerics(Map.class, String.class, Integer.class);
System.err.printf("elementType = %s%nmapType = %s%n", elementType, mapType);
}Output: elementType = com.pack.utils.ReflectionUtilsTest$UserDTO and
mapType = java.util.Map<java.lang.String, java.lang.Integer>2.18 CacheControl
Builder for HTTP Cache‑Control header values.
CacheControl cacheControl = CacheControl.maxAge(1, TimeUnit.HOURS)
.noTransform()
.mustRevalidate();
String headerValue = cacheControl.getHeaderValue();
System.err.println(headerValue);Output:
max-age=3600, must-revalidate, no-transform2.19 DefaultConversionService
Default Spring conversion service for type conversion.
DefaultConversionService conversionService = new DefaultConversionService();
Integer intValue = conversionService.convert("42", Integer.class);
Boolean boolValue = conversionService.convert("true", Boolean.class);
System.err.printf("intValue = %s, boolValue = %s%n", intValue, boolValue);Output:
intValue = 42, boolValue = true2.20 MediaTypeFactory
Detects MIME type from a filename.
Optional<MediaType> mediaType = MediaTypeFactory.getMediaType("document.pdf");
mediaType.ifPresent(System.out::println);Output:
application/pdf2.21 MimeTypeUtils
Provides common MIME type constants and utilities.
MimeType a = MimeTypeUtils.APPLICATION_JSON;
MimeType b = MimeType.valueOf("application/*");
boolean ret = a.isCompatibleWith(b);
System.err.println(ret);Output:
true2.22 PropertySource
Handles property values from custom sources.
StandardEnvironment environment = new StandardEnvironment();
Map<String, Object> props = new HashMap<>();
props.put("pack.app.title", "Spring Boot3实战案例200讲");
PropertySource<?> source = new MapPropertySource("my-properties", props);
environment.getPropertySources().addFirst(source);2.23 LocaleContextHolder
Stores the current thread's Locale for i18n.
Locale currentLocale = LocaleContextHolder.getLocale();
LocaleContextHolder.setLocale(Locale.CHINA);
System.err.println(currentLocale);Output: zh_CN All 161 cases are available for free download as a PDF, with permanent updates for subscribers.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
