【发布时间】:2018-11-26 00:36:31
【问题描述】:
我正在尝试使用 gradle、groovy 和 spring-boot 框架和以下代码构建一个简单的应用程序:
@Grab("thymeleaf-spring4")
@Controller
class ViewBasedApp {
def chapters = ["Quick Start With Groovy",
"Quick Start With Java",
"Debugging and Managing Your App",
"Data Access with Spring Boot",
"Securing Your App"]
@RequestMapping("/")
def home(@RequestParam(value="name", defaultValue="World") String n) {
new ModelAndView("home")
.addObject("name", n)
.addObject("chapters", chapters)
}
}
这是我的 build.gradle 文件:
group 'LoginApp'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile("org.springframework.boot:spring-boot-starter-web")
//compile("org.thymeleaf:thymeleaf-spring4") //first try
// compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect") //first try
compile 'org.springframework:spring-webmvc:3.0.0.RELEASE'
// https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 //secound try
compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.0.RELEASE'
// compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '4.1.6.RELEASE' //third try
}
html 文件:
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Learning Spring Boot - Chapter 1</title>
</head>
<body>
<p th:text="'Hello, ' + ${name}"></p>
<ol>
<li th:each="chapter : ${chapters}" th:text="${chapter}"></li>
</ol>
</body>
</html>
要启动我的应用程序,我使用 spring boot CLI。当我在命令提示符下使用“spring run”时,总是遇到同样的错误: 找不到工件:thymeleaf-spring4:jar: 在本地(文件:/C:/Users/kubas/repository)。
我尝试添加“thymeleaf-spring4.jar” - 从 maven 页面下载到文件夹“repository”,但什么也没有,总是同样的错误。
有人可以就此提出建议吗?
【问题讨论】:
-
此代码在没有@Grab 注释且仅在 STS 中有效
标签: spring-boot gradle groovy thymeleaf