【问题标题】:Accessing domain classes or spring beans from camel routes in Grails从 Grails 中的骆驼路由访问域类或 Spring bean
【发布时间】:2009-06-08 22:28:54
【问题描述】:

我有一个骆驼路线文件,我想根据通过 Grails 域类访问的某些数据库记录来填充/配置它。但是,我似乎无法从 MyRoute.groovy 访问域类(或 spring 上下文中的任何内容)。关于如何实现这一点的任何想法?

我尝试了Grails: Accessing spring beans in the destory closure of Bootstrap code? 的建议,但这似乎不起作用。

【问题讨论】:

    标签: spring grails apache-camel


    【解决方案1】:

    在 Java RouteBuilder 中,您可以使用 getContext() 方法获取 CamelContext。我假设您在 groovy 构建器中具有相同的方法。

    使用 CamelContext,您可以从其注册表中查找 spring bean。

    MyType foo = context.getRegistry().lookup("mySpringBean", MyType.class);

    【讨论】:

    • 你完全正确。不幸的是,这似乎并没有解决我的问题,因为在我尝试调用 serviceBean 时,它似乎还没有被 GORMified 并且无法访问数据库。
    【解决方案2】:

    你应该看看:http://camel.apache.org/hibernate.html

    请注意,您应该添加: ... ref('sessionFactory') ...

    到您的resources.groovy 中的beans 部分

    【讨论】:

    • 好吧,没有尝试,因为我们没有 .hbm.xml 文件,所以很确定它不会工作。但这非常接近我们所需要的;)
    猜你喜欢
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多