0

I want to setup Rest Controller using Spring without DispatcherServlet.

I have worked with Rest Controller with Spring MVC's dispatcher servlet but I am not sure how to setup controllers without it.

Below is the code that I tried:

@Controller
@RequestMapping("/somemapping")
public class SomeControllerImpl implements SomeController {

    @Autowired
    private SomeService service;

    @Override
    @ResponseBody
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public List<DO> getAllDO() {
        return service.getAllDO();
    }

}

When I tried accessing above controller using "localhost:8080/appName/somemapping/" it gave 404 error.

Edit: I have Websphere application server. If that has something to do with my issue.

damndemon
  • 331
  • 3
  • 11

1 Answers1

0

You can access the above controller's GET method using http://localhost:8080/somemapping/

Instead of giving @RequestMapping(value = "/"), you can also give value as value=""

Abhijeet
  • 4,069
  • 1
  • 22
  • 38
  • Thanks! I tried it but now it gave an error "servlet class was found, but a resource injection failure has occurred". – damndemon May 02 '19 at 08:15
  • The complete error is "servlet class was found, but a resource injection failure has occurred java.lang.IllegalStateException: java.lang.NoSuchMethodException: org.example.controller.SomeController.()". – damndemon May 02 '19 at 08:23
  • @damndemon share the whole stack trace. – Abhijeet May 03 '19 at 04:41
  • I think the issue is with the constructor of your controller. Are you implementing parameterized constructor without default constructor? If yes, Add a default constructor – Abhijeet May 03 '19 at 05:22