RestDefinition类型的route()方法未定义

问题描述 投票:0回答:1

@组件 公共类 BookRoute 扩展 RouteBuilder {

private final Environment env;

public BookRoute(Environment env) {
    this.env = env;
}

public void configure() throws Exception {

    restConfiguration()
            .contextPath(env.getProperty("camel.component.servlet.mapping.contextPath", "/rest/*"))
            .apiContextPath("/api-doc")
            .apiProperty("api.title", "Spring Boot Camel Postgres Rest API.")
            .apiProperty("api.version", "1.0")
            .apiProperty("cors", "true")
            .apiContextPath("doc-api")
            .port(env.getProperty("server.port", "8080"))
            .bindingMode(RestBindingMode.json);

    rest("/book")
            .consumes(MediaType.APPLICATION_JSON_VALUE)
            .produces(MediaType.APPLICATION_JSON_VALUE)
            .get("/{name}").route()
            .to("{{route.findBookByName}}")
            .endRest()
            .get("/").route()
            .to("{{route.findAllBooks}}")
            .endRest()
            .post("/").route()
            .marshal().json()
            .unmarshal(getJacksonDataFormat(Book.class))
            .to("{{route.saveBook}}")
            .endRest()
            .delete("/{bookId}").route()
            .to("{{route.removeBook}}")
            .end();

    from("{{route.findBookByName}}")
            .log("Received header : ${header.name}")
            .bean(BookService.class, "findBookByName(${header.name})");

    from("{{route.findAllBooks}}")
            .bean(BookService.class, "findAllBooks");


    from("{{route.saveBook}}")
            .log("Received Body ${body}")
            .bean(BookService.class, "addBook(${body})");


    from("{{route.removeBook}}")
            .log("Received header : ${header.bookId}")
            .bean(BookService.class, "removeBook(${header.bookId})");
}

private JacksonDataFormat getJacksonDataFormat(Class<?> unmarshalType) {
    JacksonDataFormat format = new JacksonDataFormat();
    format.setUnmarshalType(unmarshalType);
    return format;
}

}

上面的代码可以正常使用“3.3.0”,但是当我将版本更改为 “4.0.0-M3”我在routebuilder类中收到“.route()”方法的错误,提示“方法route()对于RestDefinition类型未定义” 如何解决这个问题?

spring-boot apache-camel
1个回答
0
投票

请参阅 Camel 升级指南,了解 3.16 及之后的 rest-dsl 的变化 https://camel.apache.org/manual/camel-3x-upgrade-guide-3_16.html#_rest_dsl

© www.soinside.com 2019 - 2024. All rights reserved.