spring - 从Grails看不到 Spring 启动RestController

标签 spring spring-mvc grails spring-boot grails-3.0

我已经申请了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/

相关文章:

Grails 允许 null 表示 double 不工作

grails - 将整个应用程序的varchar映射到nvarchar

数据列表中每个项目的 Spring Batch-Repeat 步骤

java - RenderRequest 上的协议(protocol)重定向

java - 在没有 Grails 的普通 Spring MVC 中使用 GSP View

java - 理解spring singleton在启动时加载实体

java - Spring MVC - 如何使用不同的映射注释调用相同的 URL

eclipse - 如何在Eclipse中指定Grails环境

java - 如何在一次测试中启动2个Spring Boot应用程序?

java - 如何将动态网站(java,spring)作为另一个网站(java)中的网页加载