Calling a Spring @Service on web application initialization -


i have web application needs static variables initialization thrown .war in tomcat webapp folder. initialization needs call @service retrieve initial set up.

i realized @autowire injection works when gui calling service

what best way initialize spring web application after throwing .war in app container? need initialization executed once only.

if need after servletcontext initialized, in spring, use applicationlistener this.

public class springlistener implements applicationlistener<contextrefreshedevent>{          // should work if other setting right           @autowired         xxx xxx;          public void onapplicationevent(contextrefreshedevent contextrefreshedevent ) {                  // things here         }     }  in application.xml <bean id="eventlistenerbean" class="package.name.springlistener " /> 

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#context-functionality-events

on otherhand, fyi, traditional way using servletcontextlistener. http://docs.oracle.com/javaee/6/api/javax/servlet/servletcontextlistener.html


Comments