Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: Is it possible to avoid lazy services initialization?

Tags:

spring

grails

I've got a service that registers JSON marshallers. I've added @PostConstruct method that registers marshallers.

But my service it's not initialized because nobody uses it. I need to inject it to initialize it. Can I mark it to initialize on Grails startup? I can inject it into BootStrap.groovy but it's obvious why BootStrap.groovy do need it

like image 679
fedor.belov Avatar asked Dec 16 '22 09:12

fedor.belov


1 Answers

Add a 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 service beans are lazy by default.

like image 109
Dónal Avatar answered Mar 15 '23 08:03

Dónal