2016-07-03 135 views
-1

是否需要执行一个步骤,比如将jar添加到classpath中?Spring Boot @RestController

我也跟着这样的:

10.2.6快速启动春季CLI例如

这里,你可以用它来测试你的安装非常简单的Web应用程序。创建一个文件名为app.groovy:

@RestController 
class ThisWillActuallyRun { 

    @RequestMapping("/") 
    String home() { 
     "Hello World!" 
    } 
} 

然后只需从shell中运行它:

$ spring run app.groovy 

,并得到:

startup failed: 
file:/home/rgupta/Documents/products/microservices/postabook/hola-springboot/app.groovy: 1: unable to resolve class ResttController, unable to find class for annotation 
@ line 1, column 1. 
@ResttController 
^ 

file:/home/rgupta/Documents/products/microservices/postabook/hola-springboot/app.groovy: 4: unable to resolve class RequestMapping , unable to find class for annotation 
@ line 4, column 5. 
@RequestMapping("/") 
^ 

2 errors 

[[email protected] hola-springboot]$ 
+2

'app.groovy'真的是你文件的内容吗?它正在寻找'ResttController'的错误信息(注意双t)听起来不对。 –

回答

1

变化@ResttController在app.groovy第1行你的IDE到@RestController

0

正如@da_mp所说,更正@RestController的拼写。完成之后,您还需要将以下导入语句添加到文件顶部:

import org.springframework.web.bind.annotation.RestController 
import org.springframework.web.bind.annotation.RequestMapping 

而且这应该可以解决您的错误。