2016-07-03 138 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 

而且這應該可以解決您的錯誤。