This library embeds a Groovy console into your Spring Boot application, providing access to the Spring context. It enables you to run Groovy scripts directly from your web browser, making it an excellent tool for testing and debugging
- GroovyScriptExecutionInterceptor – hook into script execution lifecycle
- GroovyScriptStorage - plug in your own script storage mechanism (e.g., DB, in-memory)
- CompilerConfiguration - customize the Groovy compiler settings
- Spring Boot Security (optional) - integrates seamlessly if security is enabled
This library is hosted on Jitpack. To use it, you need to add the following dependency:
Gradle Kotlin
implementation("com.github.BOOMeranGG:spring-groovy-web-console:0.1")
Gradle Groovy
implementation 'com.github.BOOMeranGG:spring-groovy-web-console:0.1'
Maven
<dependency>
<groupId>com.github.BOOMeranGG</groupId>
<artifactId>spring-groovy-web-console</artifactId>
<version>0.1</version>
</dependency>
Also, you need to add Jitpack repository to your build file:
Gradle
repositories {
maven {
url = uri("https://jitpack.io")
}
}
Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
After adding the dependency, you can open your browser and navigate to http://localhost:{port}/console
The following configurations are optional, but can be useful depending on your needs:
- To configure the library, you can change the following properties in your
application.properties
orapplication.yml
:
groovy-web-console:
enabled: true
examples:
enabled: true
api:
web-console-page:
prefix: /console
- You can implement GroovyScriptExecutionInterceptor (multiple interceptors can be registered):
interface GroovyScriptExecutionInterceptor {
fun onPreExecute(executionId: String, script: String)
fun onPostExecute(executionId: String, script: String)
fun onFailed(executionId: String, script: String, ex: Exception)
}
- And also implement GroovyScriptStorage to store and retrieve scripts (multiple storages can be registered):
fun interface GroovyScriptStorage {
fun getScripts(): List<GroovyScriptData>
}
- You can configure
org.codehaus.groovy.control.CompilerConfiguration
, for example:
@Bean
fun compilerConfiguration(): CompilerConfiguration {
val configuration = CompilerConfiguration()
val secureCustomizer = SecureASTCustomizer()
secureCustomizer.disallowedReceivers = listOf("java.lang.System")
configuration.addCompilationCustomizers(secureCustomizer)
return configuration
}
To do that, you have to install implementation 'org.apache.groovy:groovy-all:{version}'
dependency.
Contributions are welcome and appreciated - feel free to open issues or create a PR
The frontend of this library uses Monaco Editor — big thanks to the awesome team behind it!