Refactor AnnotationScanner to handle controllers without @Controller annotation gracefully and update exception messages. Adjust .idea/misc.xml structure.

This commit is contained in:
CodingPhoenix
2026-05-08 12:28:28 +02:00
parent 05c6ad3dd4
commit f19f73a2cc
2 changed files with 6 additions and 8 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_26" default="true" project-jdk-name="openjdk-26" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_26" project-jdk-name="openjdk-26" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
@@ -21,11 +21,10 @@ public final class AnnotationScanner {
public static void register(Router router, Object controller) { public static void register(Router router, Object controller) {
Class<?> clazz = controller.getClass(); Class<?> clazz = controller.getClass();
Controller ctrlAnno = clazz.getAnnotation(Controller.class); Controller ctrlAnno = clazz.getAnnotation(Controller.class);
if (ctrlAnno == null) { String prefix = "";
throw new IllegalArgumentException( if (ctrlAnno != null) {
clazz.getName() + " ist nicht mit @Controller annotiert"); prefix = normalizePrefix(ctrlAnno.value());
} }
String prefix = normalizePrefix(ctrlAnno.value());
for (Method method : clazz.getDeclaredMethods()) { for (Method method : clazz.getDeclaredMethods()) {
RouteInfo info = extractRoute(method); RouteInfo info = extractRoute(method);
@@ -48,11 +47,10 @@ public final class AnnotationScanner {
String fullPath = prefix + normalizePath(info.path()); String fullPath = prefix + normalizePath(info.path());
router.register(HttpMethod.valueOf(info.method()), fullPath, handler); router.register(HttpMethod.valueOf(info.method()), fullPath, handler);
System.out.printf("Registered: %-6s %-30s -> %s.%s%n", System.out.printf("Registered: %-6s %-30s -> %s.%s%n", info.method(), fullPath, clazz.getSimpleName(), method.getName());
info.method(), fullPath, clazz.getSimpleName(), method.getName());
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new RuntimeException("Konnte Methode nicht registrieren: " + method, e); throw new RuntimeException("Could not register method: " + method, e);
} }
} }
} }