1. Spring Run
/**
* SPRING CLI - GROOVY
* *
* Spring Boot CLI was designed specifically around Groovy as a scripting language.
* There is no real project structure like in Manve/Gradle projectd.
* You just start with:
* - app.groovy
*
* What is Spring CLI?
* - A command-line tool to quickly prototype Spring applications
* - Uses Groovy insted of Java for minimal boilerplate
* - No need to manually configure dependencies (pom)
*
* How to run:
* - Install Srping CLI (spring command)
* - Save file as: app.groovy
* - Run: spring run app.groovy
*
* Example:
* - A simple REST API
* - Minimal configuration
* - Embedded server (Tomcat)
*
* Run:
* spring run app.groovy
*
* curl http://localhost:8080
* Hello World
*
* Key Concepts:
* - No main method needed (Spring CLI auto-configures everything)
* - Embeded Server (Tomcat inside)
* - Groovy syntex (less boilerplate than Java)
* - Auto dependency resolution (Spring Boot starters included automatically)
*/
@RestController
class HelloController {
@RequestMapping("/")
String home() {
return "Hello World";
}
}
2. Spring Jar
Compile your Groovy script and package it as standalone executable JAR. Includes embeded script.
spring jar app.jar app.groovy
app.jar
3. Spring encodepassword
Encodes a password using BCrypt. Same algorithm used by Spring Security.
spring encodepassword mypass
{bcrypt}$2a$10$.A.QpyyUYOp.deCy.sSoK.q6u4NkPcdA8AqUo6ovrnfBJk0KjhzN.
4. Spring Init
Generate a real Spring Boot project. Similar to Spring initializr (start.spring.io)
spring init \
--dependencies=web,data-jpa,h2 \
--build=maven \
my-app
Generated structure:
my-app/
|__ src/
|__ pom.xml
|__ mvnw
5. Spring Version
Check spring version after installation.
sudo mkdir /opt/spring-boot
sudo tar xzf spring-boot-cli-2.6.3-bin.tar.gz -C /opt/spring-boot/
sudo gedit /etc/profile
# export SPRING_HOME=/opt/spring-boot/spring-2.6.3
# export PATH=$SPRING_HOME/bin:$PATH
source /etc/profile
spring --version # Spring CLI v2.6.3
sprint init --list