From f19f73a2cceb192523b8eb2f5ac18d4122785dca Mon Sep 17 00:00:00 2001 From: CodingPhoenix Date: Fri, 8 May 2026 12:28:28 +0200 Subject: [PATCH] Refactor `AnnotationScanner` to handle controllers without `@Controller` annotation gracefully and update exception messages. Adjust `.idea/misc.xml` structure. --- .idea/misc.xml | 2 +- .../server/annotation/AnnotationScanner.java | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 217a1af..3462391 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/src/main/java/dev/coph/nextusweb/server/annotation/AnnotationScanner.java b/src/main/java/dev/coph/nextusweb/server/annotation/AnnotationScanner.java index ef1f7d7..20ae8b1 100644 --- a/src/main/java/dev/coph/nextusweb/server/annotation/AnnotationScanner.java +++ b/src/main/java/dev/coph/nextusweb/server/annotation/AnnotationScanner.java @@ -21,11 +21,10 @@ public final class AnnotationScanner { public static void register(Router router, Object controller) { Class clazz = controller.getClass(); Controller ctrlAnno = clazz.getAnnotation(Controller.class); - if (ctrlAnno == null) { - throw new IllegalArgumentException( - clazz.getName() + " ist nicht mit @Controller annotiert"); + String prefix = ""; + if (ctrlAnno != null) { + prefix = normalizePrefix(ctrlAnno.value()); } - String prefix = normalizePrefix(ctrlAnno.value()); for (Method method : clazz.getDeclaredMethods()) { RouteInfo info = extractRoute(method); @@ -48,11 +47,10 @@ public final class AnnotationScanner { String fullPath = prefix + normalizePath(info.path()); router.register(HttpMethod.valueOf(info.method()), fullPath, handler); - System.out.printf("Registered: %-6s %-30s -> %s.%s%n", - info.method(), fullPath, clazz.getSimpleName(), method.getName()); + System.out.printf("Registered: %-6s %-30s -> %s.%s%n", info.method(), fullPath, clazz.getSimpleName(), method.getName()); } catch (IllegalAccessException e) { - throw new RuntimeException("Konnte Methode nicht registrieren: " + method, e); + throw new RuntimeException("Could not register method: " + method, e); } } }