无法在 Apache Camel 3.14.0 Spring 引导应用程序中更改 REST 上下文路径
Cannot change REST context path in Apache Camel 3.14.0 Spring Boot app
依赖项:
dependencies {
implementation("org.apache.camel:camel-core:3.14.0")
implementation("org.apache.camel:camel-openapi-java:3.14.0")
implementation("com.fasterxml.jackson.core:jackson-core:2.13.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.1")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.13.1")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.apache.camel.springboot:camel-spring-boot-starter:3.14.0")
implementation("org.apache.camel.springboot:camel-servlet-starter:3.14.0")
implementation("org.apache.camel.springboot:camel-jackson-starter:3.14.0")
implementation("org.apache.camel.springboot:camel-http-starter:3.14.0")
implementation("org.apache.camel.springboot:camel-bean-validator-starter:3.14.0")
}
尝试从 prop 文件更改:
apache-camel-spring-boot/src/main/resources/application.properties
:
camel.component.servlet.mapping.contextPath=/test/*
camel.component.servlet.mapping.context-path=/test/*
apache-camel-spring-boot/src/main/resources/application.yml
:
camel:
component:
servlet:
mapping:
contextPath: /test/*
实际 REST 配置:
@Component
public class CamelRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
.component("servlet")
.contextPath("test")
.host("localhost")
.port(8080)
.bindingMode(RestBindingMode.json)
.enableCORS(true);
rest("/users").description("User REST service")
.produces("application/json")
.get()
.outType(String.class)
.to("bean:myService?method=find")
}
}
但唯一有效的 URL 是:http://localhost:8080/camel/users
当我更改了 Camel 的上下文路径时,为什么 http://localhost:8080/test/users 返回 404?
添加到 apache-camel-spring-boot/src/main/resources/application.properties
:
camel.servlet.mapping.context-path=/*
依赖项:
dependencies {
implementation("org.apache.camel:camel-core:3.14.0")
implementation("org.apache.camel:camel-openapi-java:3.14.0")
implementation("com.fasterxml.jackson.core:jackson-core:2.13.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.1")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.13.1")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.apache.camel.springboot:camel-spring-boot-starter:3.14.0")
implementation("org.apache.camel.springboot:camel-servlet-starter:3.14.0")
implementation("org.apache.camel.springboot:camel-jackson-starter:3.14.0")
implementation("org.apache.camel.springboot:camel-http-starter:3.14.0")
implementation("org.apache.camel.springboot:camel-bean-validator-starter:3.14.0")
}
尝试从 prop 文件更改:
apache-camel-spring-boot/src/main/resources/application.properties
:
camel.component.servlet.mapping.contextPath=/test/*
camel.component.servlet.mapping.context-path=/test/*
apache-camel-spring-boot/src/main/resources/application.yml
:
camel:
component:
servlet:
mapping:
contextPath: /test/*
实际 REST 配置:
@Component
public class CamelRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
.component("servlet")
.contextPath("test")
.host("localhost")
.port(8080)
.bindingMode(RestBindingMode.json)
.enableCORS(true);
rest("/users").description("User REST service")
.produces("application/json")
.get()
.outType(String.class)
.to("bean:myService?method=find")
}
}
但唯一有效的 URL 是:http://localhost:8080/camel/users
当我更改了 Camel 的上下文路径时,为什么 http://localhost:8080/test/users 返回 404?
添加到 apache-camel-spring-boot/src/main/resources/application.properties
:
camel.servlet.mapping.context-path=/*