📅  最后修改于: 2020-11-11 05:27:27             🧑  作者: Mango
在本章中,我们将学习如何创建一个基于Thymeleaf的示例项目,以演示Spring CLI的功能。请按照以下提到的步骤创建一个示例项目-
Sr.No | Step & Description |
---|---|
1 | Create a Folder with a name TestApplication with subfolders templates and static. |
2 | Create message.groovy in TestApplication folder, message.html in templates folder, index.html in static folder as explained below. |
3 | Compile and run the application to verify the result of the implemented logic. |
@Controller
@Grab('spring-boot-starter-thymeleaf')
class MessageController {
@RequestMapping("/message")
String getMessage(Model model) {
String message = "Welcome to TutorialsPoint.Com!";
model.addAttribute("message", message);
return "message";
}
}
Spring Boot CLI Example
Spring Boot CLI Example
Go to Message
要运行该应用程序,请键入以下命令-
E:/Test/TestApplication/> spring run *.groovy
现在,Spring Boot CLI将生效,下载所需的依赖项,运行嵌入式tomcat,部署应用程序并启动它。您可以在控制台上看到以下输出-
Resolving dependencies.............................
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _> | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.8.RELEASE)
...
2017-11-08 16:27:28.300 INFO 8360 --- [ runner-0] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-11-08 16:27:28.305 INFO 8360 --- [ runner-0] o.s.boot.SpringApplication : Started application in 4.203 seconds (JVM running for 38.792)
我们的基于弹簧的休息申请现已准备就绪。以“ http:// localhost:8080 / ”打开网址,您将看到以下输出-
Go to Message
单击消息链接,您将看到以下输出-
Message − Welcome to TutorialsPoint.Com!
考虑以下几点以了解Spring CLI采取的操作-
@Grab(’spring-boot-starter-thymeleaf’)注释指示CLI下载spring-boot-starter-thymeleaf 1.5.8.RELEASE版本。
Spring CLI使用其元数据自动检测版本,因为我们在此处未指定任何组ID或版本ID。
最后,在代码编译之后,将war部署在嵌入式tomcat上,在默认端口8080上启动嵌入式tomcat服务器。