Camel Spring JavaConfig Maven-Camel-Plugin 没有任何 xml

Camel Spring JavaConfig Maven-Camel-Plugin without any xml

如何设置我的 camel 项目以完全依赖 Spring 依赖注入系统,同时使用 maven camel 运行 插件免费 xml。我已经尝试了很多配置,但我似乎仍然被 "shell context" 文件所困,该文件只导入了我的 java 配置文件。无论如何要摆脱这个?注意:也在最新的骆驼版本 2.17.1

骆驼路线

@Component
public class TestRoute extends SpringRouteBuilder {
    @Override
    public void configure() throws Exception {
        from("timer://foo?repeatCount=1")
            .log("Hello World");
    }
}

Java 配置

@Configuration
@ComponentScan("com.mcf.xml.free.route")
public class RouteJavaConfig extends CamelConfiguration {

}

Maven 骆驼插件

            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>${camel.version}</version>
                <configuration>
                    <configClasses>com.mcf.xml.free.config.RouteJavaConfig</configClasses>
                </configuration>
            </plugin>

让我想要摆脱的一切正常工作的插件上下文。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

  <context:annotation-config/>
  <bean class="com.mcf.xml.free.config.RouteJavaConfig"/>
</beans>

有没有办法让 maven camel 运行 插件接受 Java 配置而不是 Spring 上下文文件?另外我还没有测试过这个,但是如果删除这个文件会导致部署到 Apache Karaf 时出现问题,有没有办法让它也配置为使用我的 Java 配置?

我认为您的场景非常适合使用 spring boot with camel。 Spring 引用:

Absolutely no code generation and no requirement for XML configuration

在他们的页面上。 Spring-Boot

这是一个 Spring boot-camel 示例,您可以看一下以进行检查:Camel-Spring Boot example

您可以使用您自己创建的主 class 启动 Spring Java 配置应用程序,然后使用 java-maven-exec 插件 运行 它。此示例根本没有 XML 文件。

有一个示例作为 Apache Camel 的一部分,位于:https://github.com/apache/camel/tree/master/examples/camel-example-spring-javaconfig