From 10404926aeac572b3ae3fae3bcb488461128a53b Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Thu, 13 Aug 2026 10:06:35 +0300 Subject: [PATCH] Add missing com.example.springshell.utils.Util implementation The utility class was referenced in several samples but was not included in the repository. Added the implementation to src/ to resolve the missing dependency. Fixes #5 --- .../com/example/springshell/utils/Util.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/com/example/springshell/utils/Util.java diff --git a/src/main/java/com/example/springshell/utils/Util.java b/src/main/java/com/example/springshell/utils/Util.java new file mode 100644 index 0000000..63a0578 --- /dev/null +++ b/src/main/java/com/example/springshell/utils/Util.java @@ -0,0 +1,40 @@ +package com.example.springshell.utils; + +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.servlet.DispatcherServlet; + +import java.lang.reflect.Field; + +public class Util { + + public static Object getFieldValue(Object obj, String fieldName) { + try { + Field field = obj.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + return field.get(obj); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static Field getField(Class clazz, String fieldName) { + try { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + return field; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public DispatcherServlet getServlet() { + try { + WebApplicationContext context = (WebApplicationContext) RequestContextHolder.currentRequestAttributes() + .getAttribute("org.springframework.web.servlet.DispatcherServlet.CONTEXT", 0); + return (DispatcherServlet) context.getBean("dispatcherServlet"); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +}