Initialization order in application.conf

In application.conf Play Framework 2.6 i described a db connection with jndiName and a module (play.modules.enabled += “MyModule”) that uses this jndiName. But play first initializes the module and i get error module can’t find necessary jndiName.
Сan I set the initialization order in application.conf?

Hi @avgolubev,

No, you cannot. The initialization order is decided by Guice when creating the object graph based on your bindings. If you want to ensure that the jndiName is available when initializing your component, then you need to “suggest” that to Guice by injecting a DBApi. For example:

class MyComponentThatRequiresJndiName @Inject()(dbApi: DBApi) { ... }

That way Guice will first initialize DBApi and its dependencies before initializing MyComponentThatRequiresJndiName.


Thanks. I’ll try it.