@SuppressWarnings("unchecked") @Override public void contextInitialized(ServletContextEvent event) { ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(event.getServletContext()); if (registry.getRegisteredRoutes().isEmpty()) { try { List<Class<?>> routeClasses = findByAnnotation( getRoutePackages(), Route.class, RouteAlias.class).collect(Collectors.toList()); Set<Class<? extends Component>> navigationTargets = validateRouteClasses( routeClasses.stream()); RouteConfiguration routeConfiguration = RouteConfiguration .forRegistry(registry); routeConfiguration.update(() -> { routeConfiguration.getHandledRegistry().clean(); navigationTargets.forEach(routeConfiguration::setAnnotatedRoute); }); registry.setPwaConfigurationClass(validatePwaClass(routeClasses.stream())); } catch (InvalidRouteConfigurationException e) { throw new IllegalStateException(e); } } }
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Verify servlet version also for SpringBoot. ServletVerifier.verifyServletVersion(); ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(servletContext); // If the registry is already initialized then RouteRegistryInitializer // has done its job already, skip the custom routes search if (registry.getRegisteredRoutes().isEmpty()) { /* * Don't rely on RouteRegistry.isInitialized() negative return value * here because it's not known whether RouteRegistryInitializer has * been executed already or not (the order is undefined). Postpone * this to the end of context initialization cycle. At this point * RouteRegistry is either initialized or it's not initialized * because an RouteRegistryInitializer has not been executed (end * never will). */ servletContext.addListener(new RouteServletContextListener()); } servletContext.addListener(new ErrorParameterServletContextListener()); servletContext .addListener(new AnnotationValidatorServletContextListener()); }