0
0
0serd02017-01-30 09:06:24
Java
0serd0, 2017-01-30 09:06:24

What is the reason why Spring mvc controller can not be created if it contains java8 default methods?

there is a controller:

@RestController
@RequestMapping("/docs")
public class SomeController implements Controllable{
      @RequestMapping("/info")
      public ResponseEntity<String> info(){return new ResponseEntity<>("test");}
}
и 
public interface Controllable{
    @RequestMapping("/control", method=POST)
    default ResponseEntity<String> control(){ return new ResponseEntity<>("control"); }
}

If you call any of these methods by URL, in the test via mockMvc.perform(get(...)) then the value will be received,
and if you start the application, both methods will return 404, as if the controller was not created, while, in logs (at DEBUG level) there will be no errors.
Spring version: 4.3.5

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kosarev, 2017-01-30
@0serd0

In general, when the application starts, messages about request mapping appear, like:

s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/docs/info],methods=[GET]}" onto ...
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/docs/control],methods=[POST]}"  onto ...

If not, then your controller simply does not exist in the application context. If yes - see where requests are mapped.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question