Java Spring Boot MVC:URL未发布,但显示在启动日志中
我刚刚用Spring Boot(和Groovy)启动了一个非常简单的Spring MVC,但我无法正确路由我的控制器,例如:Java Spring Boot MVC:URL未发布,但显示在启动日志中,java,spring,spring-mvc,groovy,spring-boot,Java,Spring,Spring Mvc,Groovy,Spring Boot,我刚刚用Spring Boot(和Groovy)启动了一个非常简单的Spring MVC,但我无法正确路由我的控制器,例如: package net.kedare import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.stereotype.Controller
package net.kedare
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
@SpringBootApplication
class SpringLedControllerApplication {
static void main(String[] args) {
SpringApplication.run SpringLedControllerApplication, args
}
}
@Controller
@RequestMapping("/")
class SpringLedController {
@RequestMapping(method=RequestMethod.GET)
public String index() {
return "Hello"
}
}
它出现在启动日志中:
2016-01-23 14:09:28.588 INFO 57995---[main]s.w.s.m.m.a.RequestMappingHandlerMapping:将“{[/],methods=[GET]}”映射到公共java.lang.String.net.kedare.SpringleController.index()上
但当我转到URL:“”时,我得到了以下信息:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Jan 23 14:09:58 CET 2016
There was an unexpected error (type=Not Found, status=404).
No message available
看起来它重定向到/error,但我不知道为什么..在pom.xml中添加此依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
org.springframework.boot
弹簧启动装置
在pom.xml中添加此依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
org.springframework.boot
弹簧启动装置
Nice,perfect,在我的例子中,我添加它作为Gradle并添加缺少的模板,我希望只返回“Hello”字符串,因为我不知道Spring中的模板是如何工作的,但这更好:)Nice,perfect,在我的例子中,我添加它作为Gradle并添加缺少的模板,我希望只返回“Hello”字符串,因为我不知道Spring中的模板是如何工作的,但这更好:)