📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
$ spring
usage: spring [--help] [--version]
<command> [<args>]
Available commands are:
run [options] <files> [--] [args]
Run a spring groovy script
... more command help is shown here
app.groovy
@RestController
class WebApp {
@RequestMapping("/")
String greetings() {
"Spring Boot Rocks"
}
}
WebApp.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class WebApp {
@RequestMapping("/")
public String greetings() {
return "Spring Boot Rocks in Java too!";
}
public static void main(String[] args) {
SpringApplication.run(WebApp.class, args);
}
}
Spring Boot CLI Commands
The run Command
spring run [options] <files> [--] [args]
- --autoconfigure [Boolean]: Adds the auto-configuration compiler transformation.
- --classpath, -cp Adds the classpath entries, and it’s useful when you have third-party libraries.
- -- no-guess-dependencies Does not attempt to guess the dependencies. This is useful when you already use the @Grab annotation in your application.
- --no-guess-imports Does not attempt to guess the imports.
- -q, --quiet Quiets logging. In other words, it won’t print anything to the console.
- -v, --verbose Logs everything. It is useful for seeing what’s going on because it shows you even the code introspection and what is adding to the program.
- --watch Sets a watch to the file(s) for changes. It is useful when you don’t want to stop and run the app again.
$ spring run app.groovy
$ spring run app.groovy -- --server.port=8888
$ spring run WebApp.java
The test Command
spring test [options] files [--] [args]
- --autoconfigure [Boolean] Adds the auto-configuration compiler transformation (default is true).
- --classpath, -cp Adds the classpath entries, which is useful when you have third-party libraries.
- --no-guess-dependencies Does not attempt to guess the dependencies.
- --no-guess-imports Does not attempt to guess the imports.
MyTest.java
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
public class MyTest {
@Rule
public OutputCapture capture = new OutputCapture();
@Test
public void stringTest() throws Exception {
System.out.println("Spring Boot Test works in Java too!");
assertThat(capture.toString(), containsString("Spring Boot Test works in Java too!"));
}
}
$ spring test MyTest.java
The grab Command
spring grab [options] files [--] [args]
- --autoconfigure [Boolean] Adds the auto-configuration compiler transformation (default is true).
- --classpath, -cp Adds the classpath entries, which is useful when you have third-party libraries.
- --no-guess-dependencies Does not attempt to guess the dependencies.
- --no-guess-imports Does not attempt to guess the imports.
$ spring grab MyTest.java
The jar Command
spring jar [options] <jar-name> <files>
- --autoconfigure [Boolean] Adds the auto-configuration compiler transformation (default is true).
- --classpath, -cp Adds the classpath entries, which is useful when you have third-party libraries.
- --exclude A pattern to find the files and exclude them from the final JAR file.
- --include A pattern to find the files and include them in the final JAR file.
- --no-guess-dependencies Does not attempt to guess the dependencies.
- --no-guess-imports Does not attempt to guess the imports.
$ spring jar app.jar app.groovy
$ java -jar app.jar
The war Command
spring war [options] <war-name> <files>
$ spring war app.war app. groovy
$ java -jar app.war
The install Command
spring install [options] <coordinates>
spring install org.spockframework:spock-core:1.0-groovy-2.4
The uninstall Command
spring uninstall [options] <coordinates>
$ spring uninstall org.spockframework:spock-core:1.0-groovy-2.4
The init Command
spring init [options] [location]
$ spring init
The shell Command
spring shell
The help Command
spring help
Comments
Post a Comment
Leave Comment