Init method in Spring Controller (annotation version)

Krt_Malta picture Krt_Malta · Mar 24, 2011 · Viewed 127.5k times · Source

I'm converting a controller to the newer annotation version. In the old version I used to specify the init method in springmvc-servlet.xml using:

<beans>
    <bean id="myBean" class="..." init-method="init"/>
</beans>

How can I specify the init method using the annotation version?

Answer

Johan Sj&#246;berg picture Johan Sjöberg · Mar 24, 2011

You can use

@PostConstruct
public void init() {
   // ...
}