【问题标题】:How to integrate Apache Camel into a Java Spring 3.0 web application to import data如何将 Apache Camel 集成到 Java Spring 3.0 Web 应用程序中以导入数据
【发布时间】:2012-11-16 17:31:10
【问题描述】:

我正在开发一个基于 Spring 3.0 框架的 Web 应用程序。

不,我想集成 Apache Camel 以通过 CSV 文件将数据导入数据库。我设法在Apache Camel Spring Configuration example 之后运行 Camel 并在数据库中进行导入。

但现在我想将 Camel 集成到 Web 应用程序中,以便它一起启动。但我不知道该怎么做。目前,似乎 Camel 在 Web 应用程序旁边启动并使用它自己的上下文。特别是它似乎在 Web 应用程序之前启动,因为当 Camel 尝试自动连接作为 Web 应用程序一部分的数据库存储库时会引发异常。

10:57:36.730 [main] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'routeConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.data.neo4j.repository.GraphRepository com.isarsoftware.ysura.config.RouteConfiguration.graphRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in class path resource [com/isarsoftware/ysura/config/GraphDBConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.repository.GraphRepository com.isarsoftware.ysura.config.GraphDBConfig.userRepository()] threw exception; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Fri Nov 16 10:57:35 CET 2012]; root of context hierarchy

我必须承认,我离成为 Spring 专业人士还很遥远。但直到现在,我还是通过阅读博客和教程来让一切正常工作。但是对于这个问题我还没有找到任何指导。

谁能给我推荐一个教程或例子来解决我的问题?

【问题讨论】:

  • 您能否从您的 web.xml、spring servlet 上下文和骆驼上下文中发布 sn-ps,以便我了解您如何配置所有内容?
  • 还包括来自 GraphDBConfig.userRepository() 的 sn-p,因为这是引发异常的方法

标签: java spring-mvc apache-camel spring-3


【解决方案1】:

http://camel.apache.org/tutorial-on-using-camel-in-a-web-application.html

基本上,只需将 spring 监听器添加到您的 web.xml 文件中

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

然后,使用您的 CamelContext 创建一个 /WEB-INF/applicationContext.xml 文件

<beans...>
    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
          <from uri="seda:foo"/>
          <to uri="mock:results"/>
        </route>
    </camelContext>
</beans>

【讨论】:

  • 好的,是否可以使用@Configuration 注释而不是XML 文件?那么我将如何定义路线?这就是为什么我尝试遵循我在问题中提到的示例。
  • 什么是 seda:foo ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-27
  • 2011-04-23
  • 1970-01-01
  • 2014-06-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多