1

Folks,

If i understand the API correctly, method needs to be an enum, however, the following errors out.

@RequestMapping(value="/greeting",method=GET)
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
    return new Greeting(counter.incrementAndGet(),
            String.format(template, name));
}

gradle build --info errors out with


/src/main/java/hello/GreetingController.java:20: cannot find symbol
symbol  : variable GET
location: class main.java.hello.GreetingController
    @RequestMapping(value="/greeting",method=GET)

1
  • 2
    It has indeed to be an enum but you have to either use RequestMethod.GET or have an import static RequestMethod.GET to make it work. If you don't have one of those it won't work. Commented Dec 28, 2014 at 22:00

3 Answers 3

3

Try this:

@RequestMapping(value="/greeting",method=RequestMethod.GET)
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
Sign up to request clarification or add additional context in comments.

Comments

2

At the top of your java file, add the following import statement:

import static org.springframework.web.bind.annotation.RequestMethod.GET;

That should import the GET enum and you should be all set to continue coding.

This enum is part of the spring-web module. If you are e.g. using maven the following dependency is required:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.1.3.RELEASE</version>
</dependency>

2 Comments

I would not recommend import static
That may be but it would immediately solve the OPs problem.
2

This worked for me:

import org.springframework.web.bind.annotation.RequestMethod;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.