To add a listener in grails 3:
- Add doWithSpring closure to your ìnit/appName/Application.groovy
https://github.com/vahidhedayati/testwschatapp/blob/master/grails-app/init/testwschatapp/Application.groovy#L7-L11
Closure doWithSpring() {
{->
myChatConfig DefaultChatConfig
}
}
Create a file in grails-app/init/{appname}/DefaultChatConfig.groovy
https://github.com/vahidhedayati/testwschatapp/blob/master/grails-app/init/testwschatapp/DefaultWsChatConfig.groovy
package myappName
import path.to.WebsocketHomeController
import org.springframework.boot.context.embedded.ServletContextInitializer
import org.springframework.context.annotation.Bean
import javax.servlet.ServletContext
import javax.servlet.ServletException
class DefaultChatConfig {
@Bean
public ServletContextInitializer myInitializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
ServletContext.addListener(WebsocketHomeController)
}
}
}
}
You will need to sort out the import line at the top of the 2nd file import path.to.WebsocketHomeController
By the way in one my comments on the chat plugin I suggested you could make your own interfaces. By that I meant to interact with the plugin. If the plugin is doing a lot of the functionality for you but lets say you wish to manage your own users.
You could just write services in your own app that call the chat classes to view/edit/delete etc. The very same way I have shown how you add admin accounts to the chat domain classes via bootstrap in the documentation.
Some of these things takes years to fully better understand but if I wanted to be lazy I could just copy those domain classes from the chat plugin to a test project then using grails get it to generate controllers and views for them then go back to the main project and copy across the new controllers/views.
If a plugin provides functionality services/domain classes / controllers. Their all reusable locally in your main app. You can just expand or if its good then just contribute it back to the plugin itself for others to use
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…