Spring CLI (v2.1.3) can't grab spring depenencies using Grab annotation in a simple groovy file

38 views Asked by At

Bellow I'm trying to create a simple groovy file that will expose a simple service saying hello, and also handle 404 errors by implementing ErrorController ( To avoid whitelabel error page, I could inject an HttpServletRequest and retrieve the status, but this isn't my concern for now )

package org.test

@Grab("spring-boot-autoconfigure")
@Grab("spring-boot-autoconfigure-processor")

@RestController
public class HelloController implements ErrorController{

  @GetMapping(value="/hello")
  public String sayHello(){
    return "Hey Joker";
  }

  @Override
  public String getErrorPath(){
    return "/error";
  }

  @GetMapping(value="/error")
  public String notFoundException(){
   return "{error:'NOT_FOUND', message:'Resource Not Found'}";
  }
}

So when I run > spring run restController.groovy I get :

file:/Users/xxxx/yyyy/restController.groovy: 3: unable to resolve class ErrorController
 @ line 3, column 1.
   @Grab("spring-boot-autoconfigure")
   ^

1 error
1

There are 1 answers

0
Gergely Toth On BEST ANSWER

I was able to start your controller and calling the hello endpoint, by adding the following import statement (don't know why only the ErrorController import is required)

import org.springframework.boot.web.servlet.error.ErrorController