我尝试使用cdi.main
创建一个独立的驼峰org.apache.camel.cdi.Main.main();
//not org.apache.camel.Main
我还配置了deltaspike,我看到了cdi容器,但我的CamelContext没有启动。
如果有人已经运行了Camel boot cdi standalone,你能发送代码吗?
更新: 我一直在犯这种错误:
org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.AmbiguousResolutionException: There is more than one Bean with type org.apache.camel.CamelContextQualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name : ctx, Bean Owner : [ContextInitializer, WebBeansType:MANAGED, Name:null, API Types:[java.lang.Object,proj.core.ContextInitializer], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]]
found beans:
CdiCamelContext, WebBeansType:THIRDPARTY, Name:CamelContext, API Types:[org.apache.camel.CamelContext,org.apache.camel.cdi.CdiCamelContext,java.lang.Object], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any] from jar:file:/P:/atos/common/apache-maven-repo/org/apache/camel/camel-cdi/2.16.1/camel-cdi-2.16.1.jar!/org/apache/camel/cdi/CdiCamelContext.class
CamelContext, WebBeansType:PRODUCERMETHOD, Name:null, API Types:[org.apache.camel.CamelContext,org.apache.camel.SuspendableService,org.apache.camel.RuntimeConfiguration,java.lang.Object,org.apache.camel.Service], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any] from file:/P:/atos/proj-vnext/proj-core/target/classes/proj/core/CamelContextFactory.class
答案 0 :(得分:1)
如果有人遇到同样的问题,我只是发现了问题,这只是pom.xml中的配置问题。混合骆驼核心和骆驼cdi版本
这是我的工作config => camel,OpenWebBeans容器和deltaspike
* /启动应用程序的代码
org.apache.camel.cdi.Main maincdi = new org.apache.camel.cdi.Main(){};
maincdi.run();
* / camel context producer
public class CamelContextFactory {
@Produces
@ApplicationScoped
CamelContext customize() {
DefaultCamelContext context = new DefaultCamelContext();
context.setName("my-custom-camel-context");
return context;
}
void cleanUp(@Disposes CamelContext context) {
// ...
}
}
* /创建一个上下文初始化器
@ApplicationScoped
public class ContextInitializer {
@Inject
private CamelContext ctx;
@Inject
@Any
private Instance<RouteBuilder> routes;
@PostConstruct
public void init() {
// add routes
for (RouteBuilder route : routes) {
try {
ctx.addRoutes(route);
} catch (Exception ex) {
Logger.getLogger(ContextInitializer.class.getName()).log(Level.SEVERE, null, ex);
}
}
//this.ctx.start();
}
@PreDestroy
public void stop() {
//this.ctx.stop();
}
}
* /将注入&#39;路线的路线类&#39;属性
public class SomeRouteClass extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:foo?period=2000")
//.bean(testBean)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("route called from context " + exchange.getContext().getName());
}
});
}
}
* / pom.xml的一部分
<properties>
<deltaspike.version>1.7.2</deltaspike.version>
<!--<weld.version>2.3.3.Final</weld.version>-->
<owb.version>1.6.3</owb.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.deltaspike.distribution</groupId>
<artifactId>distributions-bom</artifactId>
<version>${deltaspike.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.18.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cdi</artifactId>
<version>2.18.1</version>
</dependency>
<!--delta spike core-->
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-api</artifactId>
<version>${deltaspike.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-impl</artifactId>
<version>${deltaspike.version}</version>
<scope>runtime</scope>
</dependency>
<!--container control-->
<dependency>
<groupId>org.apache.deltaspike.cdictrl</groupId>
<artifactId>deltaspike-cdictrl-api</artifactId>
<version>${deltaspike.version}</version>
<scope>compile</scope>
</dependency>
<!--open web bean dependency-->
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>${owb.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>${owb.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.1_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.2_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.cdictrl</groupId>
<artifactId>deltaspike-cdictrl-owb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
=&GT;我的错误是我有camel-core版本2.18.1和camel cdi 2.16.1