【发布时间】:2021-12-27 01:13:35
【问题描述】:
这是我的项目结构:
当我尝试通过邮递员在 ApartmentController 中调用此 get API 时,我收到 404 错误。
@RestController
@RequestMapping("/api/apartment")
class ApartmentController(private val apartmentService: ApartmentService) {
@GetMapping
fun getAllApartments(apartment: Apartment): List<Apartment> {
return apartmentService.getAllApartments()
}
@PostMapping
fun createApartment(apartment: Apartment): Apartment {
return apartmentService.createApartment(apartment)
}
}
但是,当我在主类 LeaderRealEstateApplication 中执行相同操作时,我得到了 200 个响应。
@SpringBootApplication()
class LeaderRealEstateApiApplication
fun main(args: Array<String>) {
runApplication<LeaderRealEstateApiApplication>(*args)
}
@RestController
@RequestMapping("/api/apartments")
class TestResource(private val apartmentService: ApartmentService) {
@GetMapping
fun test(): List<Apartment> {
return apartmentService.getAllApartments()
}
}
不确定我做错了什么,我尝试将其添加到我的 SpringBootApplication 注释中:
@SpringBootApplication(scanBasePackages = ["com.leaderrealestate"])
【问题讨论】:
-
你能把你所有类的包声明都加进去吗?谢谢!
标签: spring spring-boot rest kotlin http-status-code-404