In the code snippet you have provided, there is an inherent link between class A & B since they have a linked base mapping. This indicates that there is some commonality at the base class/interface level . You need to manifest and implement the same in the code as well.
You can have both the classes implement the same Interface/base class and provide base RequestMapping there.
You can then have just the method level RequestMapping in the implementation classes.
@RequestMapping("/base")
public interface BaseRestInterface{
}
@RestController
public class A implements BaseRestInterface{
@RequestMapping("/first")
methodA(){
}
}
@RestController
public class B implements BaseRestInterface{
@RequestMapping("/second")
methodB(){
}
@RequestMapping("/third")
methodC(){
}
}
The org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping would register the URLs while scanning the controller classes.
You should see the below messages in the
Tomcat console/logs:
INFO: Mapped "{[/base/first]}" onto ...A.methodA()
INFO: Mapped "{[/base/second]}" onto ....B.methodB()
INFO: Mapped "{[/base/first]}" onto ...C.methodC()
Ensure you use latest spring framework jars (Spring 5+ would be best, I think 4.3+ at least)
With Regards
Kiran Tiwari
www.sevenmentor.com