【发布时间】:2018-11-02 23:42:39
【问题描述】:
我是新的带有 spring boot 的 apache rest dsl,做了以下更改
主类
package com.javaoutofbounds.pojo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"com.ccs.batchfile"})
public class BatchFileApplication {
public static void main(String[] args) {
SpringApplication.run(BatchFileApplication.class, args);
}
}
服务类
package com.ccs.batchfile.service;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
import org.springframework.stereotype.Component;
@Component
public class BatchFileService extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration().component("servlet").bindingMode(RestBindingMode.json);
rest("/batchFile").consumes("application/json").produces("application/json").get("/routeStart").to("direct:startRoute");
}
}
路线类
package com.ccs.batchfile.routes;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ccs.batchfile.processor.StartRouteProcessor;
@Component
public class StartRoute extends RouteBuilder{
@Autowired
private StartRouteProcessor startRouteProcessor;
@Override
public void configure() throws Exception {
from("direct:startRoute").log("Inside StartRoute")
.process(startRouteProcessor);
}
}
处理器类
package com.ccs.batchfile.processor;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.springframework.stereotype.Component;
@Component("startRouteProcessor")
public class StartRouteProcessor implements Processor{
public void process(Exchange exchange) throws Exception {
String message = exchange.getIn().getBody(String.class);
System.out.println(message);
}
}
当我在邮递员中发出以下发布请求时,我无法控制 StartRouteProcessor
http://localhost:8080/batchFile/routeStart/
我使用下面的测试有效载荷来检查是否有效。
{
"title" : "test title",
"singer" : "some singer"
}
当我发布上述请求时,我收到 404 错误。请帮忙解决这个问题
【问题讨论】:
标签: spring rest spring-boot spring-camel