【发布时间】:2018-10-08 02:52:19
【问题描述】:
这是我的控制器方法
@RestController
public class ProfileController {
@GetMapping("/quiz/{quizId}/identifyfromsixjson")
@ResponseBody
UserProfileQuestion playIdentifyFromSix(@PathVariable String quizId, HttpServletRequest request) {
... Calling service method ... here
}
}
application.properties
server.contextPath=/myproject
spring.h2.console.enabled=true
spring.jpa.hibernate.ddl-auto=update
所以当我向http://localhost:8080/myproject/identifyfromsixjson/test 发出 GET 请求时,这是我在 Postman 中看到的响应。
{
"timestamp": "2018-10-08T02:42:14.387+0000",
"status": 405,
"error": "Method Not Allowed",
"message": "Request method 'GET' not supported",
"path": "/myproject/quiz/test/identifyfromsixjson"
}
启动日志
018-10-08 01:59:32.603 WARN 46035 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-10-08 01:59:32.641 INFO 46035 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/quiz/{quizId}/identifyfromsixjson]}" onto public org.springframework.http.ResponseEntity<com.myproject.model.UserProfileQuestion> com.myproject.controller.ProfileController.fetchUserProfileAndHeadShot(java.lang.String,javax.servlet.http.HttpServletRequest)
2018-10-08 01:59:32.644 INFO 46035 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-10-08 01:59:32.644 INFO 46035 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-10-08 01:59:32.672 INFO 46035 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Mapped URL path [/myproject] onto handler '/myproject'
2018-10-08 01:59:32.678 INFO 46035 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-08 01:59:32.678 INFO 46035 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
我做错了什么?
【问题讨论】:
-
您能否添加更多信息,例如您用于控制器的注释或您要返回什么?
-
在类中添加@RequestMapping("/myproject")
-
@trjade 我已经更新了我的帖子。我已将我的控制器注释为休息控制器。
-
您还有其他方法具有相同的 url 但具有 POST 映射吗?请添加完整的控制器代码。
-
@ViswanathLekshmanan 我已经在 application.properties 中指定了上下文路径
标签: spring-mvc spring-boot spring-rest