简体   繁体   English

获取404-迁移到Spring Boot 2.x后未找到消息

[英]Getting 404 - No message found after migrating to Spring Boot 2.x

After I made all the necessary changes to migrate from Spring Boot 1.5.4 to 2.1.1, I'm getting a 404 not found error. 在完成从Spring Boot 1.5.4迁移到2.1.1的所有必要更改后,出现了404 not found错误。 I think it is something with the controller's url mapping. 我认为这与控制器的网址映射有关。 I've made sure my main class and controllers are in correct place as I've placed my controller package after the main class. 我已经将我的控制器包放在主类之后,确保我的主类和控制器放置在正确的位置。 I've also used @ComponentScan and @SpringBootApplication annotations. 我还使用了@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);
        }
    }

I was able to fix it after I changed server.contextPath to server.servlet.context-path in application.properties file because from Spring Boot 2.xa number of servlet specific properties have changed from server.* to server.servlet.*. 在将application.properties文件中的server.contextPath更改为server.servlet.context-path之后,我能够修复此问题,因为从Spring Boot 2.x起,许多servlet特定属性已从server。*更改为server.servlet。*。

I hope this will be helpful. 我希望这会有所帮助。 Thanks you all for helping! 谢谢大家的帮助!

did you try @SpringBootApplication(scanBasePackages = " give your base package") 您是否尝试过@SpringBootApplication(scanBasePackages =“提供您的基本软件包”)

also the @RequestMapping(value = "user" should be @RequestMapping(value = "/user" 而且@RequestMapping(value =“ user”应该是@RequestMapping(value =“ / user”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM