Package com.vaadin.browserless
Class SpringBrowserlessApplicationContext
java.lang.Object
com.vaadin.browserless.SpringBrowserlessApplicationContext
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:
create(ApplicationContext, UnaryOperator)(and the view-package shortcuts) — returns the unsecuredBrowserlessApplicationContext.createSecured(ApplicationContext, UnaryOperator)(and the view-package shortcuts) — returns the credential-typedSecuredBrowserlessApplicationContext; requires Spring Security on the classpath.builder(ApplicationContext)— returns a pre-wiredBrowserlessApplicationContext.Builderfor full customization (e.g. a customUIFactoryor a different security handler).
var app = SpringBrowserlessApplicationContext.createSecured(springCtx,
ProtectedView.class);
var admin = app.newUser("admin", "ADMIN");
var window = admin.newWindow();
window.navigate(ProtectedView.class);
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuilder(org.springframework.context.ApplicationContext applicationContext) Creates a Spring-pre-wired builder.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.Creates an unsecured Spring-integrated application context that scans the given packages for@Route-annotated views.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.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.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.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.
-
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 customUIFactory) before callingBrowserlessApplicationContext.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 contextviewPackages- 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 contextviewPackageClasses- 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 contextconfigurer- builder configurer; e.g.b -> b.withViewPackages(...). PassUnaryOperator.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 contextviewPackages- 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 contextviewPackageClasses- 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 contextconfigurer- builder configurer- Returns:
- a new secured application context configured for Spring Security
- Throws:
IllegalStateException- if Spring Security is not on the classpath
-