如何建立在Java航线使用bean引用 [英] How to set up route in java that uses bean references
问题描述
我试图设置以下路线:
@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方法:过滤器没有
setter方法与同一类型:java.lang.String中也没有类型转换
可能的:没有可用的类型转换器从类型转换:
java.lang.String中所要求的类型:
org.apache.camel.component.file.GenericFileFilter与价值
#doneFilter
Could not find a suitable setter for property: filter as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.component.file.GenericFileFilter with value #doneFilter
我觉得我引用一个绑定的bean的方法是错误的?我绑定的所有豆类这种方式(独立应用程序):
I think the way i reference a bound bean is wrong? I bound all beans this way(stand alone app):
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中配置的路由?
So how to use beans/classes in routes configured in java?
推荐答案
骆驼预计不仅类
引用而bean实例。
Camel expects not only class
references but bean instances.
假设类有一个默认的构造函数,绑定 bean.clazz()的newInstance()
到注册表中,而不是 bean.clazz()
,我。 E:
Assuming the classes have a default constructor, bind bean.clazz().newInstance()
to the registry instead of bean.clazz()
, i. e.:
main.bind(bean.name(), bean.clazz().newInstance());
这篇关于如何建立在Java航线使用bean引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!