【发布时间】:2015-07-04 16:48:50
【问题描述】:
我已经做了一个 grails 3 应用程序
$ grails create-app helloworld
在这个中我创建了一个弹簧控制器 DemoController.groovy
package helloworld
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
/**
* A controller responding to
* curl http://localhost:8080/demo
* source location: src/main/groovy/helloworld/DemoController.groovy
*
*/
@RestController
class DemoController {
@RequestMapping("/demo")
String demo() {
"Hello demo!"
}
}
使用
$spring run src/main/groovy/helloworld/DemoController.groovy &
$curl http://localhost:8080/demo
工作正常
使用
$gradle bootrun &
$curl http://localhost:8080/demo
失败! Grails 报告无法找到 /demo
当我从一个干净的 spring boot 应用程序(由 http://start.spring.io/ 制作)做同样的事情时,它工作正常
我看不出有什么问题
【问题讨论】:
-
你必须将你的spring控制器定义为bean。您可以在
resources.groovybeans 闭包 (demoController(DemoController)) 中定义它,或将控制器包添加到grails.spring.bean.packages配置属性或使用@ComponentScan注释您的Application类
标签: spring spring-mvc grails spring-boot grails-3.0