Spring Boot CLI - Default Statements


Advertisements

In this chapter, we will learn about the Default Statements in Spring Boot CLI. To begin with, we will learn about the Default Imports.

Default Imports

Spring CLI automatically imports many libraries by default so that explicit imports are not required. Let us now consider the following groovy script to understand Default Imports.

@RestController
class FirstApplication {
   @RequestMapping("/")
   
   String welcome() {
      "Welcome to Howcodex.Com"
   }
}

Here import for @RestController, @RequestMapping annotations are already included by default by Spring Boot. We're not even require to use fully-qualified names. You can check by running the application.

Type the following command −

E:/Test/> spring run FirstApplication.groovy

The above command will generate the following output on console −

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _> | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.8.RELEASE)

...
2017-11-07 19:22:17.310  INFO 4824 --- [       runner-0] o.s.boot.SpringApplication
: Started application in 3.405 seconds (JVM running for 7.021)

Automatic Main Method

We are not required to create standard main method for groovy script to initialize a spring application. It is automatically created for spring boot application.

Advertisements