javaspring-mvc

spring-mvc controller public or package-private


What's different in public vs package-private method in the following code?

    @RequestMapping("/")
    String home(){
       "Hello World!"
    }

    @RequestMapping("/")
    public String home(){
       "Hello World!"
    }

Is it just mean public and protected in java?


Solution

  • In this case, since no one other than Spring and your unit tests should call these methods, making them public or protected doesn't change much.

    I would leave them public because