0
一個在我的應用程序的端點只能我第一次調用它,但與錯誤後未能每次:SpringBoot沒有找到處理方法,開始第二個請求
響應:
{
"timestamp": 1501295150391,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/updates"
}
日誌:
2017-07-28 19:25:50.386 DEBUG 76613 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/updates]
2017-07-28 19:25:50.386 DEBUG 76613 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /updates
2017-07-28 19:25:50.386 DEBUG 76613 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/updates]
2017-07-28 19:25:50.387 DEBUG 76613 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/updates] are [/**]
2017-07-28 19:25:50.387 DEBUG 76613 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/updates] are {}
2017-07-28 19:25:50.388 DEBUG 76613 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/updates] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[[email protected]455848]]] and 1 interceptor
2017-07-28 19:25:50.389 DEBUG 76613 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/updates] is: -1
2017-07-28 19:25:50.389 DEBUG 76613 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-07-28 19:25:50.389 DEBUG 76613 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Successfully completed request
2017-07-28 19:25:50.390 DEBUG 76613 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
2017-07-28 19:25:50.390 DEBUG 76613 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2017-07-28 19:25:50.390 DEBUG 76613 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)]
2017-07-28 19:25:50.390 DEBUG 76613 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/error] is: -1
2017-07-28 19:25:50.391 DEBUG 76613 --- [nio-8080-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Written [{timestamp=Fri Jul 28 19:25:50 PDT 2017, status=404, error=Not Found, message=No message available, path=/updates}] as "application/hal+json" using [org.springfr[email protected]e4487af]
2017-07-28 19:25:50.392 DEBUG 76613 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-07-28 19:25:50.392 DEBUG 76613 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Successfully completed request
然而,它作品第一次它被稱爲,與日誌顯示:
2017-07-28 19:55:41.085 DEBUG 77262 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/updates]
2017-07-28 19:55:41.085 DEBUG 77262 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /updates
2017-07-28 19:55:41.085 DEBUG 77262 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/updates]
2017-07-28 19:55:41.089 DEBUG 77262 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/updates] is: -1
2017-07-28 19:55:41.135 DEBUG 77262 --- [nio-8080-exec-2] m.m.a.RequestResponseBodyMethodProcessor : Written [PagedResource { content: [Resource { content: [email protected], links: [<http://localhost:8080/updates/597ad268c843e7286ab1d059>;rel="self", <http://localhost:8080/updates/597ad268c843e7286ab1d059>;rel="matchUpdate"] }, Resource { content: [email protected], links: [<http://localhost:8080/updates/597ad26ac843e7286ab1d05a>;rel="self", <http://localhost:8080/updates/597ad26ac843e7286ab1d05a>;rel="matchUpdate"] }], metadata: Metadata { number: 0, total pages: 1, total elements: 2, size: 30 }, links: [<http://localhost:8080/updates>;rel="self", <http://localhost:8080/profile/updates>;rel="profile", <http://localhost:8080/updates/search>;rel="search"] }] as "application/hal+json" using [org.springframework.data.rest.webmvc.config.Rep[email protected]c86b9e3]
2017-07-28 19:55:41.135 DEBUG 77262 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-07-28 19:55:41.136 DEBUG 77262 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Successfully completed request
- 控制器在與我的其他控制器沿頂層,所以春天應該能夠找到它
- 的應用類標註有
@ComponentScan(basePackageClasses = MatchUpdateController.class)
嘗試,並確保它位於它
相關的文件:
MatchUpdateRepository:
@RepositoryRestResource(collectionResourceRel = "updates", path = "updates")
public interface MatchUpdateRepository extends MongoRepository<MatchUpdate, String>, MatchUpdateRepositoryCustom {
List<MatchUpdate> findByReceiverId(@Param("id") String id);
}
MatchUpdateController:
@RepositoryRestController
public class MatchUpdateController {
private final MatchUpdateRepository repository;
@Autowired
public MatchUpdateController(MatchUpdateRepository repo) {
repository = repo;
}
@RequestMapping(value = "/updates", method = RequestMethod.POST)
public ResponseEntity<?> create(@RequestBody MatchUpdate update, UriComponentsBuilder builder,
@RequestHeader(value= HttpHeaders.AUTHORIZATION) String senderId) {
if (senderId == null) {
return ResponseEntity.badRequest().body("Authorization header required");
} else {
return repository.createUpdate(update, senderId, builder);
}
}
@RequestMapping(value = "/updates/{id}/accept", method = RequestMethod.POST)
public ResponseEntity<?> accept(@PathVariable("id") String id, @RequestBody MatchUpdateResponse response,
@RequestHeader(value= HttpHeaders.AUTHORIZATION) String senderId) {
if (response == null) {
return ResponseEntity.badRequest().body("Request body cannot be null");
} else {
return repository.acceptUpdate(response, id, senderId);
}
}
@RequestMapping(value = "/updates/{id}/decline", method = RequestMethod.POST)
public ResponseEntity<?> decline(@PathVariable("id") String id, @RequestBody MatchUpdateResponse response,
@RequestHeader(value= HttpHeaders.AUTHORIZATION) String senderId) {
if (response == null) {
return ResponseEntity.badRequest().body("Request body cannot be null");
} else {
return repository.declineUpdate(response, id, senderId);
}
}
}
應用:由於頁面沒有找到發生
@SpringBootApplication
@ComponentScan(basePackageClasses = MatchUpdateController.class)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}