Apache camel 在Quarkus框架中使用apache camel Bean
我正在尝试将apache camel与Quarkus一起使用。之前,我使用spring引导框架开发camel集成。所以有很多问题我仍在试图弄清楚w.r.t.Quarkus框架 关于:Bean 在春季,我可以做这样的事情Apache camel 在Quarkus框架中使用apache camel Bean,apache-camel,quarkus,Apache Camel,Quarkus,我正在尝试将apache camel与Quarkus一起使用。之前,我使用spring引导框架开发camel集成。所以有很多问题我仍在试图弄清楚w.r.t.Quarkus框架 关于:Bean 在春季,我可以做这样的事情 @Configuration public class JABXContextConfig { @Bean Unmarshaller jaxbUnmarshaller() throws JAXBException { JAXBContext ja
@Configuration
public class JABXContextConfig {
@Bean
Unmarshaller jaxbUnmarshaller() throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(MyPOJO.class );
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
return jaxbUnmarshaller;
}
}
然后我可以使用DI将它注入到类中
@Component
public class MyRestServiceRoute extends RouteBuilder {
private final JaxbDataFormat jaxb;
@Autowired
public MyRestServiceRoute(JaxbDataFormat jaxb) throws Exception{
this.jaxb = jaxb;
}
....
}
问题:
谢谢,我建议您通读Quarkus CDI文档: 还有一个使用CDI配置Camel的基本概述: 在您的示例中,
@Bean
可以由生产者方法替换,如:
public class JaxbDataFormatProducer {
@ApplicationScoped
JaxbDataFormat jaxbDataFormat() {
return new JaxbDataFormat();
}
}
而@Autowired
构造函数参数可能如下所示(如果只有一个构造函数,那么实际上不需要@Inject
):
嗨,詹姆斯,我尝试了你的建议,但出现了以下错误未能启动quarkus:java.lang.RuntimeException:io.quarkus.builder.BuildException:生成失败:由于错误而生成失败[错误]:Build step io.quarkus.arc.deployment.ArcProcessor#validate引发异常:javax.enterprise.inject.spi.DeploymentException:javax.enterprise.inject.unsatifiedResolutionException:org.apache.camel.model.dataformat.JaxbDataFormat和限定符的未满足依赖关系[@Default]`我更新了示例,以便producer方法返回一个JaxbDataFormat实例。如果您需要以某种方式对其进行定制,您可以使用该方法。
@ApplicationScoped
public class MyRestServiceRoute extends BaseRouteBuilder {
private final JaxbDataFormat jaxb;
@Inject
public MyRestServiceRoute(JaxbDataFormat jaxb) throws Exception{
super(properties);
this.jaxb = jaxb;
}
}