Spring Boot
Run BoxLang inside a Spring Boot application
The BoxLang Spring Boot Starter is a zero-configuration Spring Boot auto-configuration library that integrates the BoxLang dynamic JVM language as a view engine inside any Spring Boot 3 web application. Write your templates in BoxLang's expressive .bxm markup syntax and let Spring MVC route requests to them — no boilerplate required. You can also leverage any BoxLang features and libraries directly from your Java controllers, services, or any Spring-managed bean by just talking to the BoxRuntime API.
BoxRuntime boxlang = BoxRuntime.getInstance();✨ Features
⚙️ Zero-configuration auto-configuration — drop the JAR on the classpath and Spring Boot wires everything automatically via
BoxLangAutoConfiguration.🖼️ BoxLang View Resolver — a
BoxLangViewResolverresolves logical view names (e.g."home") to BoxLang.bxmtemplates (e.g.classpath:/templates/home.bxm).🌐 Full web scopes — templates have access to the complete set of BoxLang web scopes:
URL,Form,CGI,Cookie, andRequest.🔗 Spring Model integration — every attribute added to the Spring
Modelis automatically injected into the BoxLangvariablesscope, accessible as#variables.myKey#in the template.🔄 Lifecycle-managed runtime — the
BoxRuntimestarts early in the application lifecycle and shuts down gracefully when the context stops, with no manual wiring needed.🛠️ Configurable via
application.properties— all settings are controlled through theboxlang.*property namespace; sensible defaults require no changes for basic use.📄 Custom
boxlang.jsonsupport — supply your own BoxLang configuration file via classpath, file URI, or absolute path.🔀 Pluggable resolver order — configure the view resolver's position in the Spring MVC resolver chain so BoxLang can coexist with Thymeleaf, FreeMarker, or any other view technology.
🏷️ Spring Boot 3 / Jakarta EE ready — built against Spring Boot 3.x and the
jakarta.*namespace.
📋 Requirements
☕ Java
21+
🍃 Spring Boot
3.4.x+
🥊 BoxLang
1.11.0+
Make sure JAVA_HOME points to a JDK 21+ installation before building or running.
📦 Installation
Gradle
Maven
No @EnableBoxLang annotation or manual bean registration is required. Spring Boot's auto-configuration mechanism detects the starter on the classpath and configures everything automatically.
🚀 Quick Start
Get a BoxLang-powered Spring Boot application running in minutes.
Step 1 — Add the dependency
Add boxlang-spring-boot-starter to your project as shown in the Installation section.
Step 2 — Create a Spring MVC controller
Step 3 — Create BoxLang templates
Place .bxm templates under src/main/resources/templates/:
src/main/resources/templates/home.bxm
src/main/resources/templates/greeting.bxm
src/main/resources/templates/items.bxm
Step 4 — Run your application
Start your Spring Boot application as usual.
Important JVM Requirements: BoxLang requires reflective access to JDK internals. Ensure you pass the following JVM arguments when starting the application:
In a Gradle project, this can be added to your
bootRuntask:
Navigate to http://localhost:8080 in your browser.
⚙️ Configuration (application.properties)
application.properties)The starter registers BoxLangProperties under the boxlang.* namespace.
boxlang.prefix
String
classpath:/templates/
Directory path where .bxm templates are located.
boxlang.suffix
String
.bxm
File extension for BoxLang templates.
boxlang.config-path
String
(none)
Location of the BoxLang runtime configuration file (e.g., classpath:/boxlang.json). If not set, it defaults to checking classpath:/boxlang.json and then falls back to internal runtime defaults.
boxlang.debug-mode
boolean
false
Enables BoxLang debug mode. Useful for development logging.
boxlang.view-resolver-order
int
2147483642
The priority of the BoxLang view resolver in Spring’s resolver chain. Default is Ordered.MAX_VALUE - 5.
boxlang.runtime-home
String
(none)
Overrides the global BOXLANG_HOME environment directory.
Example application.properties
application.properties📄 BoxLang Configuration (boxlang.json)
boxlang.json)If no boxlang.config-path is set, the auto-configuration probes for classpath:/boxlang.json automatically. If that file is absent, BoxLang starts with its built-in defaults.
Place boxlang.json at src/main/resources/boxlang.json to customise language behaviour. For more info, please see the Configuration documentation.
🌐 Template Scopes & Model Integration
BoxLang templates rendered through the view engine have access to all standard BoxLang web scopes:
variables
Contains all Spring Model attributes plus template-local variables
url
Query string parameters from the HTTP request
form
Form POST data
cgi
CGI/server environment variables
cookie
HTTP cookies
request
Request-scoped storage (per HTTP request)
Accessing Spring Model attributes:
Security tip: Always use encodeForHTML() when outputting user-supplied values (e.g., URL or form parameters) to prevent XSS attacks.
🔥 Hot-Reloading Templates
By default, boxlang.prefix points at classpath:/templates/, which resolves to the compiled output directory (build/resources/main/templates/). Editing a .bxm source file has no effect until your build tool copies the updated resource — meaning a restart is usually required.
To get instant hot-reload without a restart, switch the prefix to a file: path that points directly at the source tree using a Spring dev profile.
1. Create src/main/resources/application-dev.properties
src/main/resources/application-dev.properties2. Activate the dev profile
Keep the classpath: prefix for production. The file: path works for local development but must not be used in packaged JARs or containers where the source tree is not present.
🔍 How It Works
Auto-configuration —
BoxLangAutoConfigurationis registered and activates on any Servlet-based Spring web application.Runtime lifecycle — the
BoxRuntimeis started very early in the application lifecycle, ensuring it is ready before the first HTTP request arrives. It shuts down gracefully when the application context stops.View resolution —
BoxLangViewResolverresolves logical view names to resources using the configuredprefix+viewName+suffixpattern. If the resource does not exist, it returnsnulland Spring continues to the next resolver in the chain, enabling seamless coexistence with other view technologies like Thymeleaf or FreeMarker.Template rendering —
BoxLangViewwraps theHttpServletRequestandHttpServletResponsein aSpringBoxHTTPExchange, constructs aWebRequestBoxContext(which exposes all BoxLang web scopes), injects the SpringModelmap into thevariablesscope, executes the template, and flushes the output buffer to the servlet response.
Last updated
Was this helpful?
