Jac*_*ket 7 java routes apache-camel spring-boot spring-camel
我是骆驼新手。我正在 spring-boot 中做一个项目,使用camel作为路由。我注意到,当我去 SwaggerUi 查看 Post 调用的正确功能时,路由的 contextPath 不起作用:
public void configure() {
restConfiguration().component("servlet").contextPath("service/");
rest("/ocs")
.post("/homologation")
.id(camelRoutesIdConfig.getHomologationRequestRouteId())
.consumes("application/json")
.produces("application/json")
.param()
.name("IntegrationRequestDto")
.type(RestParamType.body)
.required(true)
.description("attivazione nuovo contratto sul portale")
.endParam()
.to("direct:homologation")
}
Run Code Online (Sandbox Code Playgroud)
如果在 application.yml 中我像这样指定 contextPath ,则不会出现此问题:
camel:
rest:
component: servlet
binding-mode: json
enable-cors: true
data-format-property:
prettyPrint: false
component:
servlet:
mapping:
context-path: /service/*
Run Code Online (Sandbox Code Playgroud)
当我在一种情况下拨打 Post 电话时,它可以工作,而在路线中的 ContextPath 情况下,它无法识别该命令并给出
{
"timestamp": "2020-11-22T17:44:26.701+0000",
"status": 404,
"error": "Not Found",
"message": "Not Found",
"path": "/service/ocs/homologation"
}
Run Code Online (Sandbox Code Playgroud)
为什么会出现这个问题呢?为什么我还被迫在 application.yml 中指定,而不是在路由中仅使用一次?感谢大家提供可能的答案
确实是这样的。RestConfiguration 中的 contextPath 配置用于纯 XML-API 文档。要在调用 Get、Post、Put ... 中激活 contextPath,您需要在 application.properties 中指定它。Apache Camel 有关使用 servlet 的文档可能会对您有所帮助
| 归档时间: |
|
| 查看次数: |
3982 次 |
| 最近记录: |