Grails: Is it possible to avoid initializing lazy services?

I have a service that registers JSON marshalls. I have added the @PostConstruct method which registers marshalers.

But my service is not initialized because no one is using it. I need to enter it to initialize. Can I mark it for initialization when starting Grails? I can enter it in BootStrap.groovy, but this is obvious why BootStrap.groovy really needs it.

+4
source share
1 answer

Add lazyInit property

 class MyService { boolean lazyInit = false @PostConstruct void init() { // this will now be executed at startup because the service is eagerly created } } 

This property defaults to true if omitted, so beans services are lazy by default.

+11
source

Source: https://habr.com/ru/post/1489438/


All Articles