Spring groovy boot error: Unexpected token @@ line 45
I am trying to convert a Java controller to my Spring Boot project in Groovy and get the weirdest error when trying to compile and run
unexpected token: @ @ line 45, column 5
@RequestMapping(value = {"/v1/foo", "/foo"}, method = GET)
^
This puzzles me. Annotations - 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
}
}
source to share
So I am just dumb and missed the key differentiator between Java and Groovy
The problem is value
I am going to@RequestMapping
In Java, {"/v1/foo", "foo"}
is an array literal
In Groovy, {"/v1/foo", "foo"}
there is a closure
The error message clearly didn't help, but to fix this I just needed to change the annotation in Groovy to pass in the array literature as I assumed, not a closure
@RequestMapping(value = ["/v1/foo", "/foo"], method = GET)
source to share