0

I have a very simple Groovy script:

import org.springframework.*;

@groovy.transform.ToString()
@Controller(name="myHomeController")
class HomeController {

    String home() {

    }
}

As I use the @Controller annotation I used the menu option:

Script -> Import jars into classpath

But when compliging I receive the error:

1 compilation error:

unable to resolve class Controller ,  unable to find class for annotation
 at line: 2, column: 1

What is the correct way to use Spring Framework from the groovyConsole?

Victor M Perez
  • 2,185
  • 3
  • 19
  • 22
  • 1
    You rather need: `import org.springframework.stereotype.*` it this is gonna work. – Opal Oct 17 '18 at 08:36
  • It works now if I erase `name = "myHomeController"`, otherwise I receive this error: ` 'name'is not part of the annotation org.springframework.stereotype.Controller -> org.springframework.stereotype.Controller in @org.springframework.stereotype.Controller at line: 4, column: 1 Unexpected type java.lang.Object in @org.springframework.stereotype.Controller at line: 4, column: 18` – Victor M Perez Oct 17 '18 at 08:39
  • 1
    That's correct, `@Controller` has `value` which can be used with: `@Controller('whatever')`. – Opal Oct 17 '18 at 08:40
  • Thanks a lot. It works now. – Victor M Perez Oct 17 '18 at 08:41
  • Added an answer. – Opal Oct 17 '18 at 08:43

1 Answers1

1

For @Controller annotation you need to import:

import org.springframework.stereotype.*
Opal
  • 81,889
  • 28
  • 189
  • 210