在本章中,我们将了解Spring Boot CLI中的默认语句.首先,我们将了解默认导入.
默认导入
默认情况下,Spring CLI会自动导入许多库,因此显式导入不会需要.现在让我们考虑以下groovy脚本来理解Default Imports.
@RestControllerclass FirstApplication { @RequestMapping("/") String welcome() { "Welcome to TutorialsPoint.Com" }}
这里导入@RestController,默认情况下,Spring Boot已经包含@RequestMapping注释.我们甚至不需要使用完全限定的名称.你可以通过运行应用程序进行检查.
输入以下命令 :
E:/Test/> spring run FirstApplication.groovy
上面的命令将在控制台上产生以下输出 :
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _> | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: 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)
自动主方法
我们不需要为groovy脚本创建标准的main方法来初始化spring应用程序.它是为spring boot应用程序自动创建的.