Isai Ulate Sancho Isai Ulate Sancho - 1 year ago 114
Groovy Question

Craftercms: How to define a singleton service bean (written in groovy) in Spring?

I wrote a service (ZipService) which is being called from the Rest controllers.
I need the service to be instantiated only once and reuse it in every call.

Is there a way to define a singleton service bean written in groovy in the configuration and access it using the applicationContext object.

Answer Source

Sure, you can use the site's own Spring application context to define singleton beans. Then in your script you can do applicationContext.mybean (mybean being your bean name) to retrieve the singleton. You can get more information on the applicationContext variable in and on defining Spring beans in

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download