Spring Boot CLI - Default Statements


Advertisements


Default Imports

Spring CLI automatically imports many libraries by default so that explicit imports are not required. Consider the following groovy script.

@RestController
class FirstApplication {
   @RequestMapping("/")
   String welcome() {
      "Welcome to TutorialsPoint.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

You can see 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
E-Books Store