开源项目

知识点

相关文章

更多

最近更新

更多

Spring Boot CLI自动导入库和自动main方法

2019-04-29 23:17|来源: 网路

Spring CLI默认自动导入许多库,因此不需要显式导入。 考虑以下groovy脚本。

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

这里导入@RestController,默认情况下,Spring Boot已经包含@RequestMapping注释。 甚至不需要使用完全限定的名称。可以通过运行应用程序进行检查。


输入以下命令 -

D:\worksp\springboot-cli> spring run FirstApplication.groovy

可以在控制台上看到以下输出 -

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

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

自动main方法

不需要为groovy脚本创建标准的main方法来初始化spring应用程序。它是由spring boot应用程序自动创建的。

相关问答

更多