'@RestController @RequestMapping not working in spring boot gradle project (404 error)

I have two controllers called ControllerA and ControllerB in Kotlin&Spring project

They both have @RestController, @RequestMapping but ControllerB gets 404 error while the other works well.

// ControllerA
@RestController
@RequestMapping("/user")
class ControllerA {

    var userService: UserService = UserService();

    @GetMapping("/")
    fun userList(): Any {

        val userList: List<String> = userService.findUserList()

        if (userList.isEmpty()){
            return "no user"
        }
        return userList
    }

...


// ControllerB
@RestController
@RequestMapping("/user2")
class ControllerB (

    private val homeworkService: HomeworkService // 생성자 주입

){

    @GetMapping("/")
    fun getAllUsers() = homeworkService.getAllUser()

...


http://localhost:8080/user/ seems to call ControllerA but http://localhost:8080/user2/ doesn't work.

My package path looks like this

\package

\package\package

\package\package\packageApplication.kt

\package\package\controller

\package\package\controllerA.kt

\package\package\controllerB.kt

I think my class path is right. What's wrong with my controllers ;(



Sources

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

Source: Stack Overflow

Solution Source