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">
<file type="web" url="file://$PROJECT_DIR$" />
</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" />
</component>
</project>
@@ -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);
}
}
}