Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to invoke a method on a servlet or controller after the web container has successfully started
    primarykey
    data
    text
    <p>I am implementing a RESTful web service with Spring MVC. When the service starts, it needs to register itself so that clients can find it. I'm currently doing this in the @PostConstruct method of the @Controller class. But this registers the service before it's actually ready to receive requests, because the web container isn't yet listening for web requests. I'd prefer to register the service after the web container has finished all of its initialization and is listening for requests.</p> <p>I've looked for a listener and/or event that will notify me when the container is started, but I haven't found one. </p> <p>I may be "prematurely optimizing". The eventual full deployment environment will need to load-balance a set of replicas of each service, and the load balancer will have to take care of determining actual service availability and current load for each instance.</p> <p><strong>Edit</strong>: additional clarification.</p> <p>I want to register the service with an <em>external registry</em> (specifically, in this case, a Zookeeper instance.) I would prefer that the service not be added to the registry until the application server has <em>finished</em> initializing and is "open for business." When I use @PostConstruct, which appears to give the same basic sequencing as <code>ServletContextListener.contextInitialized()</code>, my log output looks something like this:</p> <pre><code>INFO : MyController - Registering service foo 0.1.0 at 192.168.34.15:8080 ... May 7, 2012 3:42:49 PM org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8080 May 7, 2012 3:42:49 PM org.apache.coyote.http11.Http11Protocol start INFO: Starting Coyote HTTP/1.1 on http-8080 </code></pre> <p>What I'd like to see instead is this:</p> <pre><code>INFO: Starting Coyote HTTP/1.1 on http-8080 ... INFO : MyController - Registering service foo 0.1.0 at 192.168.34.15:8080 ... </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload