我已经申请了grails 3
$ grails create-app helloworld
为此,我创建了一个 Spring Controller 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/制成)中执行相同操作时,它工作正常
我看不出有什么问题
最佳答案
我在(Grails 3 and Spring @RequestMapping)中找到了解决方案
Grails应用程序必须具有@ComponentScan到Grails应用程序Java程序包的程序包层次结构。在这种情况下,它是“helloworld”
Application.groovy(由Grails生成)现在看起来像这样:
@ComponentScan("helloworld")
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application)
}
}
关于spring - 从Grails看不到 Spring 启动RestController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29875318/