繁体   English   中英

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

[英]Camel Spring JavaConfig Maven-Camel-Plugin without any xml

我如何设置我的骆驼项目以完全依赖Spring Dependency注入系统,同时使用maven camel run插件免费使用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配置

@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 Config而不是Spring Context文件? 另外,我还没有对此进行测试,但是如果删除此文件将导致在部署到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配置

在他们的页面上。 春季启动

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM