我正在使用camel-swagger-java来公开其他API。
在web.xml中配置servlet时,有一种设置基本路径的方法:
<init-param>
<!-- we specify the base.path using relative notation, that means the actual path will be calculated at runtime as
http://server:port/contextpath/rest -->
<param-name>base.path</param-name>
<param-value>rest</param-value>
</init-param>
使用Rest DSL时有没有办法设置基本路径?
答案 0 :(得分:0)
当您配置rest-dsl时,通过调用.contextPath()
设置基本路径。来自http://camel.apache.org/swagger-java.html:
public class UserRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
// configure we want to use servlet as the component for the rest DSL
// and we enable json binding mode
restConfiguration().component("netty4-http").bindingMode(RestBindingMode.json)
// and output using pretty print
.dataFormatProperty("prettyPrint", "true")
// setup context path and port number that netty will use
.contextPath("/my/base/path/").port(8080)
// add swagger api-doc out of the box
.apiContextPath("/api-doc")
.apiProperty("api.title", "User API").apiProperty("api.version", "1.2.3")
// and enable CORS
.apiProperty("cors", "true");
// this user REST service is json only
rest("/user").description("User rest service")
.consumes("application/json").produces("application/json")
.get("/{id}").description("Find user by id").outType(User.class)
.param().name("id").type(path).description("The id of the user to get").dataType("int").endParam()
.to("bean:userService?method=getUser(${header.id})")
.put().description("Updates or create a user").type(User.class)
.param().name("body").type(body).description("The user to update or create").endParam()
.to("bean:userService?method=updateUser")
.get("/findAll").description("Find all users").outTypeList(User.class)
.to("bean:userService?method=listUsers");
}
}
您可以在.contextPath("/my/base/path/")
。