Class SpringBrowserlessApplicationContext

java.lang.Object
com.vaadin.browserless.SpringBrowserlessApplicationContext

public final class SpringBrowserlessApplicationContext extends Object
Factory for creating a Spring-integrated BrowserlessApplicationContext.

Wires a Spring-aware servlet and the BrowserlessTestSpringLookupInitializer so the test context can reach Spring beans and lifecycle. Three entry points are provided:

 var app = SpringBrowserlessApplicationContext.createSecured(springCtx,
         ProtectedView.class);
 var admin = app.newUser("admin", "ADMIN");
 var window = admin.newWindow();
 window.navigate(ProtectedView.class);
 
See Also:
  • Method Details

    • builder

      public static BrowserlessApplicationContext.Builder builder(org.springframework.context.ApplicationContext applicationContext)
      Creates a Spring-pre-wired builder. The builder has the Spring servlet, the lookup initializer and the lookup-initializer close hook configured; callers can chain additional customizations (including a custom UIFactory) before calling BrowserlessApplicationContext.Builder.build().
      Parameters:
      applicationContext - the Spring application context
      Returns:
      a pre-wired builder
    • create

      public static BrowserlessApplicationContext create(org.springframework.context.ApplicationContext applicationContext, String... viewPackages)
      Creates an unsecured Spring-integrated application context that scans the given packages for @Route-annotated views.
      Parameters:
      applicationContext - the Spring application context
      viewPackages - package names to scan for views; an empty array falls back to a full classpath scan
      Returns:
      a new unsecured application context configured for Spring
    • create

      public static BrowserlessApplicationContext create(org.springframework.context.ApplicationContext applicationContext, Class<?>... viewPackageClasses)
      Creates an unsecured Spring-integrated application context that scans the packages of the given classes for @Route-annotated views.
      Parameters:
      applicationContext - the Spring application context
      viewPackageClasses - classes whose packages should be scanned for views
      Returns:
      a new unsecured application context configured for Spring
    • create

      public static BrowserlessApplicationContext create(org.springframework.context.ApplicationContext applicationContext, UnaryOperator<BrowserlessApplicationContext.Builder> configurer)
      Creates an unsecured Spring-integrated application context, applying the given configurer to the pre-wired builder before building it.
      Parameters:
      applicationContext - the Spring application context
      configurer - builder configurer; e.g. b -> b.withViewPackages(...). Pass UnaryOperator.identity() to keep defaults.
      Returns:
      a new unsecured application context configured for Spring
    • createSecured

      public static SecuredBrowserlessApplicationContext<org.springframework.security.core.Authentication> createSecured(org.springframework.context.ApplicationContext applicationContext, String... viewPackages)
      Creates a Spring-integrated application context with Spring Security wiring that scans the given packages for @Route-annotated views. Requires Spring Security on the classpath; throws otherwise.
      Parameters:
      applicationContext - the Spring application context
      viewPackages - package names to scan for views
      Returns:
      a new secured application context configured for Spring Security
      Throws:
      IllegalStateException - if Spring Security is not on the classpath
    • createSecured

      public static SecuredBrowserlessApplicationContext<org.springframework.security.core.Authentication> createSecured(org.springframework.context.ApplicationContext applicationContext, Class<?>... viewPackageClasses)
      Creates a Spring-integrated application context with Spring Security wiring that scans the packages of the given classes for @Route-annotated views. Requires Spring Security on the classpath; throws otherwise.
      Parameters:
      applicationContext - the Spring application context
      viewPackageClasses - classes whose packages should be scanned for views
      Returns:
      a new secured application context configured for Spring Security
      Throws:
      IllegalStateException - if Spring Security is not on the classpath
    • createSecured

      public static SecuredBrowserlessApplicationContext<org.springframework.security.core.Authentication> createSecured(org.springframework.context.ApplicationContext applicationContext, UnaryOperator<BrowserlessApplicationContext.Builder> configurer)
      Creates a Spring-integrated application context with Spring Security wiring, applying the given configurer to the pre-wired builder. Requires Spring Security on the classpath; throws otherwise.
      Parameters:
      applicationContext - the Spring application context
      configurer - builder configurer
      Returns:
      a new secured application context configured for Spring Security
      Throws:
      IllegalStateException - if Spring Security is not on the classpath