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



我怎样才能将我的骆驼项目设置为完全依赖 Spring 依赖注入系统,同时使用 maven 骆驼运行插件获得 xml 自由。 我已经尝试了大量的配置,但我似乎仍然被一个只导入我的 java 配置文件的"shell 上下文"文件所困扰。 有没有办法摆脱这个?注意:也在最新的骆驼版本2.17.1上

骆驼路线

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

Java Config

@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 骆驼运行插件接受 Java 配置而不是 Spring 上下文文件? 我还没有测试过这个,但是如果删除这个文件会导致部署到 Apache Karaf 的问题,有没有办法让它也配置为使用我的 Java Config?

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

作为

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

我认为

您的方案非常适合将弹簧靴与骆驼一起使用。春季语录:

绝对无需生成代码也无需 XML 配置

在他们的页面上。弹簧靴

这是一个弹簧靴-骆驼示例,您可以查看检查: 骆驼弹簧靴示例

最新更新