我正在尝试设置以下路线:
@Override
public void configure() throws Exception {
log.info("Creating ftp rout from " + config.ftpUrl().split("\\?")[0]);
from(config.ftpUrl()
+ "&stepwise=true"
+ "&delay=1000"
+ "&move=${file:name}.trans"
+ "&recursive=true"
+ "&binary=true"
+ "&filter=#" + Beans.doneFilter.name()
+ "&maxMessagesPerPoll=200"
+ "&eagerMaxMessagesPerPoll=false"
+ "&sorter=#" + Beans.sorter.name())
.log("Downloading file ${file:name}")
.to("file:" + config.ftpTargetPostpaid())
.to("file:" + config.ftpTargetPrepaid())
.to("file:" + config.ftpTargetFonic())
//.routePolicyRef(Beans.policy.name())
.autoStartup(false)
.routeId("ftp");
}
错误是:
无法为属性找到合适的setter:filter as asnn&t; t 具有相同类型的setter方法:java.lang.String和类型转换 可能:没有类型转换器可用于转换类型: java.lang.String到所需的类型: 带有值的org.apache.camel.component.file.GenericFileFilter #doneFilter
我认为我引用绑定bean的方式是错误的?我以这种方式绑定所有bean(独立应用程序):
public class MainApp {
/**
* A main() so we can easily run these routing rules in our IDE
*/
public static void main(String... args) throws Exception {
Injector i = Guice.createInjector(new CepModule());
Main main = new Main();
bindBeans(main);
main.enableHangupSupport();
main.addRouteBuilder(i.getInstance(FetchFtp.class));
main.run();
}
private static void bindBeans(Main main) {
for (Beans bean : Beans.values()) {
main.bind(bean.name(), bean.clazz());
}
}
/**
* This is the java style bean registry. Use the enums name as reference to the bean.
*
*
*/
public static enum Beans{
sorter(SortingStrategy.class),
policy(PolicyForStartAndStopRoutes.class),
doneFilter(ExcludeDoneFilesFilter.class);
private final Class<?> clazz;
Beans(Class<?> clazz){
this.clazz = clazz;;
}
public Class<?> clazz(){
return clazz;
}
}
}
那么如何在java中配置的路由中使用bean / classes?
答案 0 :(得分:1)
Camel不仅要求class
引用,还要求bean实例。
假设类具有默认构造函数,请将bean.clazz().newInstance()
绑定到注册表而不是bean.clazz()
,i。 E:
main.bind(bean.name(), bean.clazz().newInstance());