Spring Boot + Tomcat:RequestMappingHandlerMapping不映射请求

时间:2018-02-22 15:36:39

标签: java spring tomcat spring-boot

我使用Spring Boot + Tomcat。为了获得战争,我接下来要执行:

apply plugin: 'war'

war {
    enabled = true
}

compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '1.5.10.RELEASE'

&安培;继承SpringBootServletInitializer的应用程序:

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            return builder.sources(Application.class);
        }
...

之后,战争开始在tomcat中运行,但是有一个问题 - 请求没有映射到RequestMappingHandlerMapping,就像他们必须:

2018-02-15 14:05:01 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/health/activity/all],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<ru.example.dto.impl.ActivityDto>> ru.example.controller.impl.ActivityController.getAll(com.querydsl.core.types.Predicate,org.springframework.data.domain.Pageable)

&安培;等等。试图找到需要的地址我看到了:

{
    "timestamp": 1518692962027,
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/health/member"
}

日志:

2018-02-15 14:46:53 [http-nio-8080-exec-9] WARN  o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/health/member] in DispatcherServlet with name 'dispatcherServlet'

控制器类看起来像这样:

@Controller
@RequestMapping(value = "/health/program")
public class ProgramController extends AbstractCrudController {

@GetMapping(value = "/calculate", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<ProgramPackDto> getPrograms(@RequestParam("id") Long id,
                                                         @RequestParam("weight") Double weight) {
        return service.getProgram(id, weight).map(d -> new ResponseEntity<>(d, HttpStatus.OK))
                .orElseGet(() -> new ResponseEntity<>(ResponseEntityUtils.createHeaders(), HttpStatus.OK));
    }
}

请帮我解决问题。

0 个答案:

没有答案