2

since I need to serve two APIs which controllers are very similar in most of all cases and therefore I'd like to work with abstract controllers and sub controllers in order to achieve routes like:

/sym/products
/frontend/products

Where the "sym" or "frontend" part should be generated by abstract superclasses (controllers) like

@RestController
@CrossOrigin
@RequestMapping("sym")
public abstract class SymphonyBaseController {}

and

@RestController
@CrossOrigin
@RequestMapping("frontend")
public abstract class FrontendBaseController {}

so I could do:

@RestController
@CrossOrigin
@RequestMapping("products")
public class ProductController extends SymphonyBaseController {}

Btw: are these annotations (@RestController and @CrossOrigin) in the subclasses necessary anyway when annotated in super class already?)

My problem: The routes are not being registered. I only get a single route: /products

How to fix this?

I'd really appreciate your help! Thanks in advance,

Tim

1 Answer 1

4

Values for the exact same parameter override on subclasses, they don't accumulate. Path parameters on controller methods are appended to any mapping defined on the class (and so you could, for example, put /products on an abstract method if you like), but you'll need to specify the full base path.

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

Comments

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.