Liferay 7 MessageListener osgi module

594 Views Asked by At

When I worked with the liferay 6.1 I created an application that received the message.

Java class:

    public class MailMessageBus implements MessageListener

\src\main\webapp\WEB-INF\src\META-INF\messaging-spring.xml file:

<beans 
default-destroy-method="destroy" 
default-init-method="afterPropertiesSet"
xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="messagingConfigurator" class="com.liferay.portal.kernel.messaging.config.PluginMessagingConfigurator">
    <property name="messageListeners">
        <map key-type="java.lang.String" value-type="java.util.List">
            <entry key="mail-send-message">
                <list value-type="com.liferay.portal.kernel.messaging.MessageListener">
                    <ref bean="messageListener.mail_listener" />
                </list>
            </entry>
        </map>
    </property>
    <property name="destinations">
        <list>
            <ref bean="destination.mail"/>
        </list>
    </property>

</bean>

<!-- Destination class -->
<bean id="destination.mail" class="com.liferay.portal.kernel.messaging.ParallelDestination">
        <property name="name" value="mail-send-message" />
</bean>
<!-- Listener class -->
<bean id="messageListener.mail_listener" class="customportlet.AMessageBusListener.MailMessageBus" />

and \src\main\webapp\WEB-INF\web.xml file:

...
<context-param>
    <param-name>portalContextConfigLocation</param-name>
    <param-value>/WEB-INF/src/META-INF/messaging-spring.xml</param-value>
</context-param>
...

How can I do the same for liferay 7 in the OSGi module? OSGi module does not have a web.xml file. Thank you very much!

1

There are 1 best solutions below

0
On

I'm trying to accomplish the same thing, and based on what I've found so far the web.xml is unnecessary. OSGi modules seem to detect spring configuration automatically, according to this resource:

https://docs.spring.io/spring-osgi/docs/current/reference/html/app-deploy.html

Just put your configuration in xml files located at META-INF/spring