DocsCore concepts

Core concepts

Services & injection

Keep your existing Spring habits. Inject services into components and give page state the right lifetime.

Browse documentation

Use ordinary Spring services

Jaspring creates components through Spring’s bean factory, so constructor injection works without another container. Keep business rules and external I/O behind services, then pass the results into component state.

ProfileComponent.java
@Component(selector = "app-profile", templateUrl = "profile.component.html")
public class ProfileComponent {
    private final UserDirectory directory;

    public ProfileComponent(UserDirectory directory) {
        this.directory = directory;
    }
}

Give state a page lifetime

Spring services are singletons by default. A mutable singleton is shared across visitors. Use @Scope("jaspring-page") for a bean that should be owned by one live page. The scope is available during rendering, event handlers, and tracked continuations.

DraftState.java
@org.springframework.stereotype.Service
@org.springframework.context.annotation.Scope("jaspring-page")
public class DraftState {
    private String title = "Untitled";

    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }
}

Return to a page turn

Zone.current().fork(work) performs work outside the page turn on a virtual thread. Its continuation runs as a new turn, under the page lock. That is the safe place to update the component’s page-owned signals.

Loading in a component
public void load() {
    Zone.current().fork(directory::findAll)
            .thenAccept(users::set);
}
Jaspring · release + master guidesRead the framework source