Spring is often associated with servers, yet complex desktop applications benefit just as much from dependency injection, structured configuration, data access, and lifecycle management. With Spring Boot’s embedded web server and Fuzio’s embedded Chromium view, you can pair a Spring Boot backend with a Vue 3 frontend inside a single Java desktop executable.
In this tutorial, we build the architecture step by step and compare two communication patterns:
- Option A: Embedded HTTP server + REST APIs
- Option B: Custom URL scheme + Java↔JS bridge (no local HTTP port)
Project Structure
spring-fuzio-desktop-demo/
├── pom.xml
├── src/main/
│ ├── java/tech/fuzio/demo/
│ │ ├── DesktopApplication.java
│ │ ├── dashboard/
│ │ └── user/
│ └── resources/
│ ├── application.yml
│ └── static/
└── web-app/
├── package.json
├── vite.config.ts
└── src/
├── pages/
├── components/
└── api/
Step 1: Boot Spring Boot for a Desktop Process
Spring Boot defaults to headless mode (headless(true)), which throws HeadlessException when creating Swing frames. Explicitly disable headless mode using SpringApplicationBuilder:
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class DesktopApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context =
new SpringApplicationBuilder(DesktopApplication.class)
// .web(WebApplicationType.NONE)
.headless(false)
.run(args);
}
}
- For Option A (embedded Tomcat + REST), keep the default web mode.
- For Option B (custom scheme + JS bridge), pass
.web(WebApplicationType.NONE)to run Spring purely as a DI container.
For Option A, configure application.yml to bind only to loopback on an ephemeral port:
server:
port: 0
address: 127.0.0.1
Read the assigned port at startup:
import org.springframework.boot.web.context.WebServerApplicationContext;
int port = ((WebServerApplicationContext) context).getWebServer().getPort();
String appUrl = "http://127.0.0.1:" + port + "/";
Step 2: Render the Vue UI with Fuzio
Add Fuzio dependencies via Maven or Gradle:
plugins {
id 'tech.fuzio.gradle' version '1.0.0'
}
fuzio {
version = '2026.3.0'
}
dependencies {
implementation fuzio.currentPlatform
implementation fuzio.swing
}
Embed Fuzio’s BrowserView inside a Swing JFrame:
var engine = Engine.newInstance(HARDWARE_ACCELERATED);
var browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
var view = BrowserView.newInstance(browser);
var frame = new JFrame("Spring + Fuzio Desktop App");
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
engine.close();
}
});
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(1280, 800);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.navigation().loadUrl(appUrl);
});
Fuzio runs Chromium in separate native processes over IPC, so any renderer crash leaves your Spring Boot backend process alive.
Step 3: Option A — Embedded Server + REST
Expose a standard @RestController:
@RestController
@RequestMapping("/api/dashboard")
public class DashboardController {
private final DashboardService dashboardService;
public DashboardController(DashboardService dashboardService) {
this.dashboardService = dashboardService;
}
@GetMapping("/summary")
public Map<String, Object> summary() {
return Map.of(
"statCards", dashboardService.statCards(),
"revenueChart", dashboardService.revenueChart());
}
}
Call it from Vue with fetch:
export async function fetchSummary(): Promise<DashboardSummary> {
const res = await fetch('/api/dashboard/summary')
if (!res.ok) throw new Error('Failed to load dashboard data: ' + res.status)
return res.json()
}
In production, even when binding to
127.0.0.1, pass a per-launch local token via headers so other local processes cannot invoke local endpoints.
Output the Vite build directly to src/main/resources/static:
export default defineConfig({
plugins: [vue()],
base: './',
build: {
outDir: fileURLToPath(new URL('../src/main/resources/static', import.meta.url)),
emptyOutDir: true,
},
})
Step 4: Option B — Custom Protocol + Java↔JS Bridge
If you do not want to open a local HTTP port or expose frontend assets over localhost, serve packaged classpath assets using Fuzio’s custom Scheme interceptor and call Spring beans directly over the Java↔JS bridge.
Serve Frontend Assets via Custom Scheme
var engine = Engine.newInstance(
EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.addScheme(Scheme.of("app"), interceptor)
.build());
Load the bundled frontend directly without a local port:
browser.navigation().loadUrl("app://my-app.com");
Communicate via the Java↔JS Bridge
Expose a Spring bean annotated with @JsAccessible:
@Component
@JsAccessible
public class SpringBridge {
private final UserService userService;
public SpringBridge(UserService userService) {
this.userService = userService;
}
public String listUsers() {
return new Gson().toJson(userService.findAll());
}
}
Inject it via InjectJsCallback:
SpringBridge bridge = context.getBean(SpringBridge.class);
browser.set(InjectJsCallback.class, params -> {
params.frame().<JsObject>executeJavaScript("window").putProperty("springBridge", bridge);
return InjectJsCallback.Response.proceed();
});
Invoke it from TypeScript:
declare const springBridge: {
listUsers(): string
}
const users = JSON.parse(springBridge.listUsers())
See the Fuzio JavaScript Guide for more bridge patterns.
Further Reading
Add a Chromium-based browser engine to your Java desktop app with Fuzio.
Try for free

