Spring Boot GetMapping 404

Viewed 444

I'm studying Java Spring Boot. But my get request always return 404, but my post request could succeed. I'm so confused. Here is my Java code:

@Controller
public class LexicalAnalysisController {


    @CrossOrigin 
    @GetMapping(value = "api/LexicalAnalysis/test")
    public String test(){
        return "111";
    }


}

Here is my javaScript code:

scan(){
        this.$axios
          .get('/LexicalAnalysis/test')
          .then((response) => {
            console.log(reponse.data);
          })
          
          .catch(failResponse =>{

          })
        
      }

Here is my error information:

enter image description here

So what's wrong? Thank you very much!

4 Answers

either change @controller to @RestController or add @ResponseBody below @controller. ResponseBody annotation binds a method return value to the web response body therefore it is required.

You should replace @Controller with @RestController.

This link maybe helpful.

I changed @Controller to @RestController and it worked, but I still don't know why.

Change @Controller to @RestController This will do the job

Related