Is there any spring way in initializing when loading MVC?
Let's say I need to create global objects based on configuration files, is there a place for this or just create my own servlet and do it in oninit?
How about a standard one @PostConstruct?
@PostConstruct
@Service class AnySpringBean { @PostConstruct public void init() { //run when bean is created } }
Also works with @Controller.
@Controller
UPDATE: ContextLoaderListener) contextInitialized() web.xml (. user1076371 answer). , Spring bean.
ContextLoaderListener
contextInitialized()
web.xml
ApplicationListener, , . , - , , Spring . , , "", , .
, Spring bean, , bean PostStartupBean, .
public void onApplicationEvent( ApplicationEvent applicationEvent ) { if ( applicationEvent instanceof ContextRefreshedEvent ) { ..do stuff here.. } }
Spring. beans ( ..) . , Spring , ContextLoaderListener web.xml.
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4"> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> </web-app>
WebApplicationContext .