【发布时间】:2018-12-19 20:02:51
【问题描述】:
在完成从 Spring Boot 1.5.4 迁移到 2.1.1 的所有必要更改后,我收到 404 not found 错误。我认为这与控制器的 url 映射有关。 我已确保我的主类和控制器位于正确的位置,因为我已将控制器包放在主类之后。 我还使用了@ComponentScan 和@SpringBootApplication 注解。
@RestController
@RequestMapping("/feature")
public class FeatureController {
@RequestMapping(value = "user", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String getFeatureForuser(@PathVariable("user_id") String userEId) {
LOGGER.info("Fetching the avaliable features for User: {}", userEId);
// Invoke the service layer.
return service.getFeatureForuser(userEId);
}
}
【问题讨论】:
-
也许是
value = "/user"?或者可能由于某些原因更改了应用根目录 -
你在哪里(哪个包)添加了
@ComponentScan? -
也许你在不是
FeatureController包的父包的包中添加了@SpringBootApplication -
@Spara 我在 FeatureController 的父包中添加了 SpringBootApplication。
标签: java spring-boot