Class BrowserlessApplicationContext.Builder

java.lang.Object
com.vaadin.browserless.BrowserlessApplicationContext.Builder
Enclosing class:
BrowserlessApplicationContext

public static class BrowserlessApplicationContext.Builder extends Object
  • Constructor Details

    • Builder

      public 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 Details

    • withViewPackages

      public BrowserlessApplicationContext.Builder withViewPackages(String... packages)
      Adds packages to scan for @Route-annotated views. Successive calls accumulate. Ignored when this builder was created with an explicit Routes instance.
      Parameters:
      packages - package names to scan
      Returns:
      this builder
      Throws:
      NullPointerException - if packages or any element is null
    • withViewPackages

      public BrowserlessApplicationContext.Builder withViewPackages(Class<?>... 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
      Throws:
      NullPointerException - if classes or any element is null
    • withComponentTesterPackages

      public BrowserlessApplicationContext.Builder withComponentTesterPackages(String... packages)
      Adds packages to scan for ComponentTester implementations annotated with Tests. Successive calls accumulate. Each package is scanned at most once per JVM (see TesterRegistry).
      Parameters:
      packages - package names to scan for testers
      Returns:
      this builder
      Throws:
      NullPointerException - if packages or any element is null
    • withComponentTesterPackages

      public BrowserlessApplicationContext.Builder withComponentTesterPackages(Class<?>... classes)
      Adds the packages of the given classes to the set of packages to scan for ComponentTester implementations annotated with Tests. Successive calls accumulate.
      Parameters:
      classes - classes whose packages should be scanned for testers
      Returns:
      this builder
      Throws:
      NullPointerException - if classes or any element is null
    • withSecurityContextHandler

      public <C> SecuredBrowserlessApplicationContext.Builder<C> withSecurityContextHandler(SecurityContextHandler<C> handler)
      Sets the security context handler for multi-user auth isolation and transitions to a credential-typed SecuredBrowserlessApplicationContext.Builder. The base builder's accumulated state (servlet factory, UI factory, lookup services, close hooks) is carried over.
      Type Parameters:
      C - the credentials type accepted by the handler
      Parameters:
      handler - the handler; must not be null
      Returns:
      a secured builder configured with the given handler
      Throws:
      NullPointerException - if handler is null
    • withServletFactory

      public BrowserlessApplicationContext.Builder withServletFactory(BiFunction<com.vaadin.browserless.internal.Routes,com.vaadin.browserless.internal.UIFactory,VaadinServlet> factory)
      Sets a custom servlet factory. The factory receives the routes and the UIFactory configured via withUIFactory(UIFactory) (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
      Throws:
      NullPointerException - if factory is null
    • withUIFactory

      public BrowserlessApplicationContext.Builder withUIFactory(com.vaadin.browserless.internal.UIFactory uiFactory)
      Sets the UI factory used when creating UI instances for this application's windows. Defaults to a factory producing MockedUI instances.
      Parameters:
      uiFactory - the UI factory
      Returns:
      this builder
      Throws:
      NullPointerException - if uiFactory is null
    • withLookupServices

      public BrowserlessApplicationContext.Builder withLookupServices(Class<?>... 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
      Throws:
      NullPointerException - if services or any of its elements is null
    • withCloseHook

      public 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
      Throws:
      NullPointerException - if hook is null
    • build

      Builds the application context.
      Returns:
      a new application context