'Does writing each rest api in it's own specific java file will help in performance boost even though they have the same base path

For example, I have two rest APIs with the same base path.

First REST API

api1.java -> Annotated with @RestController

@RestController("/basepath")

public class Api1 {

    @GetMapping("/path1")
    public String gethelloWorld(){
       return "Hello World";
     }

}

Second REST API api2.java -> Annotated with @RestController

@RestController("/basepath")

public class Api2 {

    @GetMapping("/path2")
    public String getGreetings(){
       return "Hii there!!";
     }

}

So here we can see that there are two api's with same base path. But there are placed in two different java file. So follwing this approach. Will it have any advantage or any disadvantage if write I rest controller like this. As I am placing two get methods in their own java file.



Solution 1:[1]

There are no benefits in placing those two methods in different classes. And while technically it would work it makes no sense to do so. Since you have them in the same base path placing them into 2 different classes makes it very inconvenient and error prone for support. So, I'd say that there is no good reason to do so. They should be in the same class

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Gantman