0

I need a way to get called when the start of the current EAR services are done. Specifically web services. The @PostConstruct annotation is usefull, but too early. A commented pseudo server.log should show the problem:

// All JNDI bindings get established
[2020-05-19... Portable JNDI names for EJB TemplateCreator: [java:global/AllInOne/L...]

// @PostConstruct methods get called. Far too early.
[2020-05-19... Trying to interact with web services failed]

// Starting of web services
[2020-05-19... Mojarra 2.3.14... for context '/app' gets initialized]

[2020-05-19... Loading application [AllInOne#TheApp.war] at [/app]]]

// Other web services get started the same...

// ========== This! Exactly here I need the call! Not earlier! =================

What would be the alternative to @PostConstruct which gets called at the right moment?

Jan
  • 1,032
  • 11
  • 26
  • 1
    Don't know which type of web services you have, but you could try to use a @WebListener. See example here: https://stackoverflow.com/a/60384068/4962355 – Christoph John May 19 '20 at 20:24
  • While that sounds promising... Would that work if the @WebListener class is outside of the deployed WAR? – Jan May 20 '20 at 07:08
  • TBH I don't know. If you want a specific WAR to be started lastly maybe you can assign it a different deployment order via `--deploymentorder` – Christoph John May 20 '20 at 08:43
  • Actually I solved it already this way. I created an extra WAR around my target class, so I could deploy it last, and then the methods I need are called at the right time. But: It's actually a bit messy to have a complete WebService, just as a container so the method gets called at the right time. – Jan May 20 '20 at 14:58

0 Answers0