Grails 3 : Adding listeners to a plugin

509 views
Skip to first unread message

Vahid Hedayati

unread,
Apr 20, 2015, 12:33:00 PM4/20/15
to grails-de...@googlegroups.com
Hi All

Tried a lot of different things and not go very far:

I raised this question a while back in regards to doWithWebDescriptor:

http://stackoverflow.com/questions/28902928/grails-grails3-dowithwebdescriptor

of course as Joshua pointed out this is now all via spring boot.

I have tried the variations of the example provided from the other link provided by Joshua none of which appears to be actually working as in a basic default tomcat listener which appears not to even return test printlns etc..


According to : http://java.dzone.com/articles/spring-boot-my-favorite


To implement a custom listener one can use addListener of SpringApplication or add it to context.listener.classes property. An attempt to implement SpringApplicationRunListener to listen to the lifecycle of Spring Boot will not succeed because the implementations of this interface will be loaded only from META-INF/spring.factories. So, the way to have access to the Spring Boot lifecycle is to implement ApplicationListener that EventPublishingRunListener will publish the events to accordingly. In this phase EventPublishingRunListener publishes the ApplicationStartedEvent event and all registered listeners can react upon it.


I have tried a lot of variations including:

class WsChatEndpoint extends ChatUtils  implements ServletContextListener, ApplicationListener<ContextStartedEvent> {
class WsChatEndpoint extends ChatUtils implements ServletContextListener,ApplicationListener<ParentContextAvailableEvent> {


I still get no test log back from any of those listener interfaces..

I am just wondering if what I ask is even possible under spring boot with grails or should I start looking at spring websocket to work alongside spring boot ?

Regards
Vahid



Vahid Hedayati

unread,
May 5, 2015, 7:01:06 AM5/5/15
to grails-de...@googlegroups.com

Hi All

I have managed to get default tomcat websocket listener to work via a spring boot grails app:

It is documented here:

https://github.com/vahidhedayati/testwebsocket-grails3

Regards
Vahid
Reply all
Reply to author
Forward
0 new messages