Spring Boot API with Multiple Controllers?

后端 未结 8 1059
孤城傲影
孤城傲影 2021-02-07 12:36

I am starting to learn Spring Boot. I am struggling to find an example with multiple RestControllers, which indicates to me that I may be doing something wrong. I am trying a ve

8条回答
  •  逝去的感伤
    2021-02-07 13:04

    Try below:-

    @ComponentScan
    @Configuration
    @EnableAutoConfiguration
    public class BootDemoApplication {
    
    public static void main(String[] args) {
    
        SpringApplication.run(BootDemoApplication.class);
    }
    }
    
    @RestController
    @RequestMapping(value = "test", produces =    MediaType.APPLICATION_JSON_VALUE)
    public class TestController {
    
    @RequestMapping(method = RequestMethod.GET)
    public String test() {
        return "from test method";
    }
    
    }
    

提交回复
热议问题