0

I have the below setup in my Spring Boot app:

@RestController
@RequestMapping ("/main/**")
class Child extends Parent {
// Child code
}

abstract class Parent {
// Other code
@RequestMapping ("/sub/**")
public ResponseEntity handle(RequestEntity re) {

 // Expected to handle requests with path pattern /main/sub/**

}

The goal is to have the handle() method in abstract Parent Controller to receive all incoming requests for the path pattern "/main/sub/**".

But it's not working. Though it works if I place the handle method (from Parent Controller) inside the Child Controller along with its request mapping.

Can someone help me identify what I'm missing here?

More detailed code below as suggested by Ralf:

    @RestController
    @RequestMapping ("/main/**")
    class Child<T> extends Parent<T> {
    // Child code only overrides those methods defined in the parent, and has no request mapping for any method within this class. And it does not override the handle() method defined in parent.
    }

    abstract class Parent<T> {
    // Other code
    @RequestMapping ("/sub/**")
    public @ResponseBody ResponseEntity<?> handle(RequestEntity<T> re) {
     // Expected to handle requests with path pattern /main/sub/
    }
}

1 Answer 1

1

Just tried your example, works as expected, except for one case: If there is a method handle(RequestEntity) in your child controller, than this overrides the one in your parent controller, and it will never be called. If this is not the case, could you please provide your child controllers code?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for looking. I have added detailed code in my post above. There is no significant difference except that the updated one is using a class template variable <T>. I wonder if this has anything to do with request mapping failure.

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.