2

I am using OSGI with Spring MVC,details are as follows

Bundle b1-declares message source as bean. the message resource is success fully autowired in a service in bundleb1. Entry for Message Source in xml is

<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>

Message source is exposed as a service in osgi-context.xml of bundle b1 as follows

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

To import the message resources in the WAB bundle, have made following entry in osgi-context.xml of WAB have made following entry to import the messageSource service exposed by bundle b1.

Note - i have not created messageSource bean in WAB(not defined messageSource in *-servlet.xml) as i expect the messageSource to be imported from Bundle B1 and be used by spring for lang resolution.

Problem is -when i hit sample Jsp placed in WAB i recieve error

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

Analysis- Further debugging the spring code i found that messagesource used in webapplication context is of type DelegatingMessageSource. But the messageSource imported from bundle b1 expose object of type InitializableMessageSource. This means webapplication context is not initialized with messageSource that is imported through osgi-context.xml of WAB.

PLS help...

Amit
  • 77
  • 3

1 Answers1

1

In your consumer bundle, add the following to your sping config:

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

Then, you can inject the messageSource-bean as you would do with a local bean.

mbelow
  • 1,093
  • 6
  • 11
  • Hi, have added in the osgi-context.xml of the consumer bundle, Still not working because messageSource is not getting autowired to spring webapplicationcontext. messageSource in resolveMessage function of spring MessageTag class shows that messageSource is of DelegatingMessageSource – Amit Dec 10 '12 at 07:09
  • I would start with something very simple to see if your service gets correctly exported as an OSGi service. In your consumer bundles activator, try to aquire the service manually (via getServiceReference, and then getService). Note that spring DM exports the beans under the fully qualified name of the interface. – mbelow Dec 10 '12 at 10:41
  • To check this i autowired message source in a controller. I am getting the object of type InitializableMessageSource as expected. – Amit Dec 12 '12 at 05:20