Spring Boot Groovy编译错误:意外令牌@ @第45行 [英] Spring Boot groovy compilation error: Unexpected token @ @ line 45
问题描述
我正在尝试将Spring Boot项目中的Java控制器转换为Groovy,并在尝试编译和运行时遇到最奇怪的错误
I'm trying to convert a Java controller in my Spring Boot project to Groovy, and getting the strangest error when trying to compile and run
unexpected token: @ @ line 45, column 5
@RequestMapping(value = {"/v1/foo", "/foo"}, method = GET)
^
这让我感到困惑.注解是Java或Groovy中的注解,对吗?我想念什么?这是我的代码的抽象
This is baffling to me. Annotations are annotations in Java or Groovy, right? what am I missing? Here's an abstraction of my code
// src/main/groovy/my/package/FooController.groovy, formerly .java
/// ... proper imports
@RestController
@EnableAutoConfiguration
public class FooController {
// ... @autowire services
@RequestMapping(value = {"/v1/foo", "/foo"}, method = GET)
public ResponseEntity get(@RequestHeader HttpHeaders headers) {
// do work return ResponseEntity
}
@RequestMapping(value = {"/v1/foo", "/foo"}, method = PUT)
public ResponseEntity put(@RequestHeader HttpHeaders headers, @ResponseBody @Valid final MyFoo myFoo) {
// do work return ResponseEntity
}
}
推荐答案
所以我很傻,错过了Java和Groovy之间的关键区别
So I'm just dumb and missed a key differentiator between Java and Groovy
问题是我传递给@RequestMapping
在Java中,{"/v1/foo", "foo"}
是数组文字
In Java, {"/v1/foo", "foo"}
is an array literal
在Groovy中,{"/v1/foo", "foo"}
是一个闭包
In Groovy, {"/v1/foo", "foo"}
is a closure
错误消息显然没有帮助,但是要解决此问题,我只需要更改Groovy中的注释即可按我的意图传递数组文字,而不是闭包
The error message obviously wasn't helpful, but to fix this I simply needed to change the annotation in Groovy to pass in an array literal as I intended, not a closure
@RequestMapping(value = ["/v1/foo", "/foo"], method = GET)
这篇关于Spring Boot Groovy编译错误:意外令牌@ @第45行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!