diff --git a/vaadin-spring/src/main/java/com/vaadin/flow/spring/ReloadCache.java b/vaadin-spring/src/main/java/com/vaadin/flow/spring/ReloadCache.java index 273a0cd0bb3..40446a3ecb8 100644 --- a/vaadin-spring/src/main/java/com/vaadin/flow/spring/ReloadCache.java +++ b/vaadin-spring/src/main/java/com/vaadin/flow/spring/ReloadCache.java @@ -29,6 +29,7 @@ class ReloadCache implements Serializable { static Set skippedResources = new HashSet<>(); static Set dynamicWhiteList; static Set routePackages; + static Set layoutPackages; static Set jarClassNames = new HashSet<>(); static Set> jarClasses = new HashSet<>(); } \ No newline at end of file diff --git a/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java b/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java index 52cd193c24a..3983e8bb19c 100644 --- a/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java +++ b/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java @@ -327,7 +327,7 @@ public void failFastContextInitialized(ServletContextEvent event) { getLogger().debug("There are no discovered routes yet. " + "Start to collect all routes from the classpath..."); try { - Collection routePackages = null; + Collection routePackages; if (devModeCachingEnabled && ReloadCache.routePackages != null) { routePackages = ReloadCache.routePackages; @@ -356,11 +356,27 @@ public void failFastContextInitialized(ServletContextEvent event) { "There are {} navigation targets after filtering route classes: {}", navigationTargets.size(), navigationTargets); + Collection layoutPackages; + if (devModeCachingEnabled + && ReloadCache.layoutPackages != null) { + layoutPackages = ReloadCache.layoutPackages; + } else { + layoutPackages = getDefaultPackages(); + } + Set> layoutClasses = findByAnnotation( - routePackages, Layout.class) + layoutPackages, Layout.class) .collect(Collectors.toSet()); + + if (devModeCachingEnabled) { + ReloadCache.layoutPackages = layoutClasses.stream() + .map(Class::getPackageName) + .collect(Collectors.toSet()); + } + RouteRegistryInitializer .validateLayoutAnnotations(layoutClasses); + // Collect all layouts to use with Hilla as a main layout layoutClasses.stream().filter( clazz -> RouterLayout.class.isAssignableFrom(clazz))