Class BrowserlessApplicationContext.Builder
-
- All Implemented Interfaces:
public class BrowserlessApplicationContext.BuilderBuilder for creating a customized BrowserlessApplicationContext.
Calling withSecurityContextHandler transitions to a SecuredBrowserlessApplicationContext.Builder whose build() returns the credential-typed SecuredBrowserlessApplicationContext.
-
-
Constructor Summary
Constructors Constructor Description BrowserlessApplicationContext.Builder()Creates a builder with no pre-seeded routes.
-
Method Summary
Modifier and Type Method Description BrowserlessApplicationContext.BuilderwithoutRoutes()Disables @Routediscovery for this builder by seeding an empty Routes instance.BrowserlessApplicationContext.BuilderwithViewPackages(Array<String> packages)Adds packages to scan for @Route-annotated views.BrowserlessApplicationContext.BuilderwithViewPackages(Array<Class<out Object>> classes)Adds the packages of the given classes to the set of packages to scan for @Route-annotated views.BrowserlessApplicationContext.BuilderwithComponentTesterPackages(Array<String> packages)Adds packages to scan for ComponentTester implementations annotated with Tests. BrowserlessApplicationContext.BuilderwithComponentTesterPackages(Array<Class<out Object>> classes)Adds the packages of the given classes to the set of packages to scan for ComponentTester implementations annotated with Tests. <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. BrowserlessApplicationContext.BuilderwithServletFactory(BiFunction<Routes, UIFactory, VaadinServlet> factory)Sets a custom servlet factory. BrowserlessApplicationContext.BuilderwithUIFactory(UIFactory uiFactory)Sets the UI factory used when creating UI instances for this application's windows. BrowserlessApplicationContext.BuilderwithLookupServices(Array<Class<out Object>> services)Adds the given Vaadin Lookup service classes to the set configured for this builder. BrowserlessApplicationContext.BuilderwithCloseHook(Runnable hook)Registers a hook to be invoked when the built application context is closed. BrowserlessApplicationContextbuild()Builds the application context. -
-
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
@Routediscovery 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<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
-
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
-
withComponentTesterPackages
BrowserlessApplicationContext.Builder withComponentTesterPackages(Array<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
-
withComponentTesterPackages
BrowserlessApplicationContext.Builder withComponentTesterPackages(Array<Class<out Object>> 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
-
withSecurityContextHandler
<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.
- Parameters:
handler- the handler; must not benull- Returns:
a secured builder configured with the given handler
-
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
UIFactorythrough the builder ensures the servlet uses the same factory as BrowserlessUIContext window creation, so paths like the legacyafterSessionClosesession-recreation hook don't end up producing UIs of a different type. When unset, a default servlet that uses the configuredUIFactoryis created by build.- Parameters:
factory- the servlet factory- Returns:
this builder
-
withUIFactory
BrowserlessApplicationContext.Builder withUIFactory(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
-
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
-
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 fromclose()as a single RuntimeException with the originals attached as suppressed exceptions.- Parameters:
hook- the hook to register; must not benull- Returns:
this builder
-
build
BrowserlessApplicationContext build()
Builds the application context.
- Returns:
a new application context
-
-
-
-