Java 如何在驼峰路线中使用上下文路径?
我不熟悉骆驼。我正在做一个项目在春季开机使用骆驼路线。我注意到,当我转到SwaggerUi查看Post调用的正确功能时,路由的contextPath不起作用:Java 如何在驼峰路线中使用上下文路径?,java,spring-boot,routes,apache-camel,spring-camel,Java,Spring Boot,Routes,Apache Camel,Spring Camel,我不熟悉骆驼。我正在做一个项目在春季开机使用骆驼路线。我注意到,当我转到SwaggerUi查看Post调用的正确功能时,路由的contextPath不起作用: public void configure() { restConfiguration().component("servlet").contextPath("service/"); rest("/ocs") .post
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")
}
如果在application.yml中指定如下上下文路径,则不会出现此问题:
camel:
rest:
component: servlet
binding-mode: json
enable-cors: true
data-format-property:
prettyPrint: false
component:
servlet:
mapping:
context-path: /service/*
在一种情况下,当我使用callpost时,它可以工作,而在routes中使用ContextPath时,它无法识别命令并发出命令
{
"timestamp": "2020-11-22T17:44:26.701+0000",
"status": 404,
"error": "Not Found",
"message": "Not Found",
"path": "/service/ocs/homologation"
}
为什么会有这个问题?为什么我还要在application.yml中指定,而不是在路由中只使用一次?感谢大家提供了一个可能的答案它这样工作是正确的。RestConfiguration中的contextPath配置用于纯XML-API文档。要激活通话中的contextPath,请获取、发布、放置。。。您需要在application.properties中指定它。Apache Camel关于使用servlet的文档可能会帮助您在应用程序上添加属性配置。属性: camel.component.servlet.mapping.context path=/camel-rest示例/* 然后打电话 http://localhost:8080/camel-rest示例/${your resource here}