Class BrowserlessApplicationContext.Builder

    • Constructor Detail

      • BrowserlessApplicationContext.Builder

        BrowserlessApplicationContext.Builder()

        Creates a builder with no pre-seeded routes. Routes are derived from the view packages configured on this builder (or from a full classpath scan when none are configured) at build time.

    • Method Detail

      • withoutRoutes

         BrowserlessApplicationContext.Builder withoutRoutes()

        Disables @Route discovery for this builder by seeding an empty Routes instance. build then skips the classpath scan entirely, which is the desired behaviour for ad-hoc component testing where no routed views are needed. Any view packages configured via withViewPackages are ignored once this is set (an explicit Routes instance always wins).

        Returns:

        this builder

      • withViewPackages

         BrowserlessApplicationContext.Builder withViewPackages(Array<Class<out Object>> classes)

        Adds the packages of the given classes to the set of packages to scan for @Route-annotated views. Successive calls accumulate. Ignored when this builder was created with an explicit Routes instance.

        Parameters:
        classes - classes whose packages should be scanned
        Returns:

        this builder

      • withServletFactory

         BrowserlessApplicationContext.Builder withServletFactory(BiFunction<Routes, UIFactory, VaadinServlet> factory)

        Sets a custom servlet factory. The factory receives the routes and the UIFactory configured via withUIFactory (or its default), and must return a fully configured VaadinServlet. Wiring the UIFactory through the builder ensures the servlet uses the same factory as BrowserlessUIContext window creation, so paths like the legacy afterSessionClose session-recreation hook don't end up producing UIs of a different type. When unset, a default servlet that uses the configured UIFactory is created by build.

        Parameters:
        factory - the servlet factory
        Returns:

        this builder

      • withLookupServices

         BrowserlessApplicationContext.Builder withLookupServices(Array<Class<out Object>> services)

        Adds the given Vaadin Lookup service classes to the set configured for this builder. Successive calls accumulate; the builder starts with an empty set. Calling with no arguments is a no-op.

        Parameters:
        services - the service implementation classes to add
        Returns:

        this builder

      • withApplicationProperty

         BrowserlessApplicationContext.Builder withApplicationProperty(String name, String value)

        Sets a Vaadin application property (init parameter) for this application. A previously set value for the same name is replaced.

        Parameters:
        name - the property name; must not be null
        value - the property value; must not be null
        Returns:

        this builder

        Since:

        25.3

      • withFeatureFlags

         BrowserlessApplicationContext.Builder withFeatureFlags(Array<String> featureIds)

        Enables the given Vaadin feature flags for this application, overriding the values potentially defined in the vaadin-featureflags.properties file or in system properties.

        Parameters:
        featureIds - the identifiers of the features to enable; must not be null
        Returns:

        this builder

        Since:

        25.3

      • withFeatureFlags

         BrowserlessApplicationContext.Builder withFeatureFlags(Array<Feature> features)

        Enables the given Vaadin feature flags for this application, overriding the values potentially defined in the vaadin-featureflags.properties file or in system properties.

        Parameters:
        features - the features to enable; must not be null
        Returns:

        this builder

        Since:

        25.3

      • withFeatureFlag

         BrowserlessApplicationContext.Builder withFeatureFlag(String featureId, boolean enabled)

        Enables or disables the given Vaadin feature flag for this application, overriding the value potentially defined in the vaadin-featureflags.properties file or in system properties.

        Parameters:
        featureId - the identifier of the feature; must not be null
        enabled - true to enable the feature, false to disable it
        Returns:

        this builder

        Since:

        25.3

      • withFeatureFlag

         BrowserlessApplicationContext.Builder withFeatureFlag(Feature feature, boolean enabled)

        Enables or disables the given Vaadin feature flag for this application, overriding the value potentially defined in the vaadin-featureflags.properties file or in system properties.

        Parameters:
        feature - the feature; must not be null
        enabled - true to enable the feature, false to disable it
        Returns:

        this builder

        Since:

        25.3

      • withConfiguration

         BrowserlessApplicationContext.Builder withConfiguration(BrowserlessConfiguration testConfiguration)

        Applies the given custom Vaadin configuration to this builder, replacing previously set entries with the same names.

        Useful to reuse a configuration declared with BrowserlessTestConfig on a test class:

        BrowserlessApplicationContext.create(b -> b.withViewPackages(MyView.class)
                .withConfiguration(BrowserlessConfiguration.from(getClass())));
        
        Parameters:
        testConfiguration - the configuration to apply; must not be null
        Returns:

        this builder

        Since:

        25.3

      • withCloseHook

         BrowserlessApplicationContext.Builder withCloseHook(Runnable hook)

        Registers a hook to be invoked when the built application context is closed.

        Hooks run in registration order, after users and the Vaadin service have been torn down, exactly once (subsequent close() calls are no-ops). They are intended for releasing framework-specific state attached during context creation — for example, Spring's lookup-initializer ThreadLocal. A throwing hook does not prevent the remaining hooks from running; any thrown RuntimeExceptions are collected and surfaced from close() as a single RuntimeException with the originals attached as suppressed exceptions.

        Parameters:
        hook - the hook to register; must not be null
        Returns:

        this builder