【问题标题】:OSGI - Not able to access Application resources loaded in a service bundleOSGI - 无法访问服务包中加载的应用程序资源
【发布时间】:2012-12-07 18:52:51
【问题描述】:

我正在使用OSGI和Spring MVC,详情如下

Bundle b1-将消息源声明为 bean。消息资源在 bundleb1 中的服务中完全自动装配成功。 xml 中消息源的条目是

<bean id="messageSource" class="org.synyx.messagesource.InitializableMessageSource">
<property name="basename" value="ApplicationResources"/>
<property name="messageProvider">
    <bean class="org.synyx.messagesource.jdbc.JdbcMessageProvider">
        <property name="dataSource" ref="dataSource"/>            
    </bean>
</property>
</bean>

消息源在 bundle b1 的 osgi-context.xml 中作为服务公开,如下所示

 <osgi:service interface="org.springframework.context.MessageSource" ref="messageSource"/>

要导入WAB bundle 中的消息资源,在WAB 的osgi-context.xml 中做了如下的条目 已经做了以下条目来导入bundle b1 暴露的messageSource 服务。

注意 - 我没有在 WAB 中创建 messageSource bean(未在 *-servlet.xml 中定义 messageSource),因为我希望从 Bundle B1 导入 messageSource 并由 spring 用于语言解析。

问题是 - 当我点击放置在 WAB 中的示例 Jsp 我收到错误

javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'user.nametext' for locale 'en_US'.

分析-进一步调试spring代码我发现webapplication上下文中使用的messagesource是DelegatingMessageSource类型。但是从 bundle b1 导入的 messageSource 暴露了 InitializableMessageSource 类型的对象。 这意味着 webapplication context 没有使用通过 WAB 的 osgi-context.xml 导入的 messageSource 初始化。

请帮忙...

【问题讨论】:

    标签: spring-mvc osgi spring-dm


    【解决方案1】:

    在您的消费者捆绑包中,将以下内容添加到您的 sping 配置中:

    <osgi:reference id="messageSource" interface="org.springframework.context.MessageSource" />
    

    然后,您可以像使用本地 bean 一样注入 messageSource-bean。

    【讨论】:

    • 您好,已在消费者捆绑包的 osgi-context.xml 中添加 ,但仍然无法正常工作,因为messageSource 没有自动连接到 spring webapplicationcontext。 spring MessageTag类的resolveMessage函数中的messageSource显示messageSource属于DelegatingMessageSource
    • 我会从一些非常简单的事情开始,看看您的服务是否被正确导出为 OSGi 服务。在您的消费者捆绑激活器中,尝试手动获取服务(通过 getServiceReference,然后通过 getService)。请注意,spring DM 以接口的完全限定名称导出 bean。
    • 为了检查这一点,我在控制器中自动装配了消息源。我按预期获得了 InitializableMessageSource 类型的对象。
    猜你喜欢
    • 2013-10-23
    • 2011-04-01
    • 2023-03-03
    • 2012-09-28
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 2014-04-27
    • 2015-05-04
    相关资源
    最近更新 更多